Affects Version/s: 6.0.12 EE, 6.2.0 CE M2
Running 5.2.3, I was able to reproduce these characters getting in the database, which is most likely why the Permission upgrade is failing.
Steps to reproduce special characters:
1. Startup Liferay 5.2.3
2. Click on the maximize button of any portlet
You'll notice the URL changes: http://localhost:8080/web/guest/home?p_p_id=47
3. Change the p_p_id to something random, like http://localhost:8080/web/guest/home?p_p_id='aasafdsfdsafsd'
4. Press enter.
You'll notice that this p_p_id is written to the ResourceCode table.
This part has been resolved and no longer an issue.
5. Upgrade to Liferay 6.0.x or 6.1.x (I tested with 6.0.x and 6.0.12)
Make sure to keep permissions.user.check.algorithm=5
6. Convert permissions to 6, via Control Panel
You'll get a stacktrace regards to special characters.