marcrobledo / RomPatcher.js

An IPS/UPS/APS/BPS/RUP/PPF/xdelta ROM patcher made in HTML5.
https://www.marcrobledo.com/RomPatcher.js/
Other
723 stars 141 forks source link

BUG FIX: Prevent truncation when the patched file is larger than the original. #46

Closed hotelvictorcharlie closed 2 years ago

hotelvictorcharlie commented 2 years ago

Hello!

Over at the HTGDB we noticed some unexpected behavior when the patched rom's file size is larger than the original. In our case we were trying to apply this patch to a 128KB rom which should give us a 512KB rom, but it was actually truncating the patched rom to the first 128KB.

I haven't tested this fix very thoroughly but it seems to work (that is, it gives me the same output as Lunar IPS, Flips, etc.). But I've only spent a few minutes grokking this code so please don't assume that I know what I'm doing.

marcrobledo commented 2 years ago

Thank you!

This seems to be an odd case where the IPS patch has the truncate flag set to a bigger size than the original ROM, which makes no sense (that would not be truncating but expanding the ROM). However, looks like both Lunar IPS and FLIPS apply the patch correctly, so I figure that's the expected behaviour.

Though the solution works for your patch, it is now breaking other patches. The slice function had already a correct behaviour so it shouldn't be changed. So, unfortunately, I'm going to reject this PR and implement the fix in the IPS module instead, as this is an issue with the IPS format, not the slice function (which again, it was working as it should).

But again, thanks for your warning! :-)