EmuNewz Network
Savefile corruption in r2690 - Printable Version

+- EmuNewz Network (https://www.emunewz.net/forum)
+-- Forum: PSP Emulation (https://www.emunewz.net/forum/forumdisplay.php?fid=191)
+--- Forum: JPCSP Official Forum (https://www.emunewz.net/forum/forumdisplay.php?fid=51)
+---- Forum: svn trunk discussion (https://www.emunewz.net/forum/forumdisplay.php?fid=56)
+---- Thread: Savefile corruption in r2690 (/showthread.php?tid=78996)



Savefile corruption in r2690 - Itaru - 08-25-2012

The changes in r2690, specifically jpcsp.HLE.kernel.types.SceUtilitySavedataParam are causing savefile corruption when savedata crypto mode is enabled. Line 505 is truncating the encrypted savedata improperly:
Code:
505    fileOutput.write(outBuf, 0, Math.min(length, outBuf.length));
The CryptoEngine produces encrypted savedata that is a few bytes larger than the original savedata, so forcing the encrypted output to be same length as the original is causing the data corruption. I believe line 505 should be reverted to:
Code:
505    fileOutput.write(outBuf);

Another problem is line 527:
Code:
527    int length = Math.min(outBuf.length, Math.min(fileSize, maxLength));
As long as the decrypted data is smaller than the encrypted data, then this code is harmless. However, if it ever happens that the decrypted data is bigger than the encrypted data, then improper truncation will occur during loading. I think the proper code should be:
Code:
527    int length = Math.min(outBuf.length, maxLength);

Finally, I believe line 531 should be:
Code:
531    return length;



RE: Savefile corruption in r2690 - gid15 - 08-26-2012

This should now be fixed as suggested in r2704.
Thank you for reviewing the code! Smile