-
Notifications
You must be signed in to change notification settings - Fork 562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
json_data: Autorepair corrupted project files #3259
Conversation
If a file is detected as having corrupted unicode escapes, we make a backup copy as filename.osp.bak (or filename.osp.bak.1...), then regexp-replace all of the broken escapes with corrected ones. Then we run the file through json.loads() and json.dumps() again to remove the escaped characters, and write the results back to the original file location as UTF-8.
@ferdnyc This looks good to me! Perhaps we can remove this code at a future point. But for sure, our next release should include it. 👍 Thanks for the help. |
There is case where full name (start of it) was missing from the project file (bottom of the message): #3258 (comment) |
Side Note: the auto-saving (enabled by default) can convert any just opened (!) v2.4.4 file into release version 2.5.0 with all consequences of escaping and shortening if something not fully loaded. And user will be unaware that files were overwritten. |
@SuslikV This PR only auto-converts project files with "2.5.0" as the version. It would ignore v2.4.4 files. Maybe I'm misunderstanding you though. |
@jonoomph I think @SuslikV is saying that the current 2.5.0 will create (corrupted) 2.5.0-type files out of good 2.4.4 project files, if autosave is enabled. Nothing to do with this PR, but it does potentially multiply the impact vector for the exporting bug. When 2.5.0 autosaves a formerly-2.4.4 project file, it'll update the version in its JSON data to |
At the risk of being self-indulgent, I'd just like some recognition for the fact that I was totally able to come up with a plausible example of a file path that would trigger a false positive in the corruption-detection code. 😉 |
Seems like we clobber the "version" attribute on save, meaning any previous version data always gets updated, and your logic stands true! |
The file sample from the #3258 Also, after repair (on Windows) file has no |
Hmmm...
But I'm not sure why relative path transforms would create
It's expected that it wouldn't have CRLF endings, yeah. It does contain CR line endings, so WordPad should display it properly, along with any advanced editor like Notepad++, etc. |
It don't. What daily build surely has the fix? Maybe some daily builds error?
Yes. The v2.4.4 (where |
I did tests. The next code removes
Edit:
|
mystery behind There is |
Yeah, sorry, I read your original message too fast the first time.
Which is
...THAT'S where things break down.
Yeah, which is wrong. It needs to go back to the original I can't just assume that any I can make a couple of assumptions, though, to make the recovery smarter:
I'll add those rules to the repair logic, and hopefully that will cover most or all of these cases.
It does, but the wrong way (for our purposes).
Normpath normalizes paths to the current OS, whereas we (for some reason) want to force the paths to one specific format regardless of OS. Python has no tools for doing that. (Which in and of itself feels like a really good reason to think twice about whether it's the right approach.) Regardless, the issue right now isn't whether we should be doing it. It's already been done, so now we have to correct for it regardless. |
If a file is detected as having corrupted unicode escapes, we make
a backup copy as filename.osp.bak (or filename.osp.bak.1...), then
regexp-replace all of the broken escapes with corrected ones. Then
we run the data through json.loads() and json.dumps() again to remove
the escaped characters, and write the results back to the original
file location as UTF-8.
There's a slight danger of false positives on the corrupted-file detection, which is why a backup is made of the original data before it's rewritten.
Also, as an added safety check, the repair will only run on project files matching
"openshot_qt".*"2.5.0
(meaning, they're tagged as created by 2.5.0). That way, we don't accidentally edit users' OpenShot 2.4.4 projects that import files from their$HOME/Music/ub404eva/
directory.