mame icon indicating copy to clipboard operation
mame copied to clipboard

CHDMAN: creating delta chd using parent chd with large size and small hunk will report error

Open crashGG opened this issue 1 year ago • 5 comments

MAME version

0.271 , 0.272 , 0.273, , ,

System information

Win10 22h2 , AMD zen4 7840HS

Incorrect behaviour

In some cases,creating delta chd using parent chd with large size and small hunk will report error:

CHD error occurred: Hunk out of range Error during compression: Hunk out of range Fatal error occurred: 1

But when I changed chdman back to 0.270, the compression went smoothly.

Expected behaviour

compression went smoothly like 0.270

Steps to reproduce

1, specify the hunk size as 2048 to make chd file. for example: chdman createdvd -c zstd,flac,huff,lzma -hs 2048 -i "Soulcalibur III (Japan) (En,Ja) (v2.00).chd" -o "ori.chd" 2,Modify some data on the original iso (e.g. simply modify a few bytes). Then create a delta for the parent using the previous chd. for example: chdman createdvd -i "modded.iso" -op "ori.chd" -o "new.chd"

Additional details

I tested several larger iso that exhibited the problem: Soulcalibur III (Japan) (En,Ja) (v2.00).iso Berserk - Millennium Falcon-hen - Seima Senki no Shou (Japan).iso

crashGG avatar Nov 29 '24 12:11 crashGG

In addition, the earliest problematic commit that can be traced back is this https://github.com/mamedev/mame/commit/43584224ebb63b6fbc6c01c9e5cc0d4b36ed6366

crashGG avatar Nov 29 '24 21:11 crashGG

How big do the files have to be to observe this behaviour?

cuavas avatar Feb 26 '25 13:02 cuavas

When the iso size exceeds 4G and use 2048 hunk size. You can try the ps2 iso in your hand, and it is very likely that this issue can be reproduced.

crashGG avatar Feb 26 '25 13:02 crashGG

The underlying issue that it wants to get away with reading past the end if the parent CHD was there before 0.270, but it just didn’t check for errors reading the parent CHD at all. Adding error checking exposed it.

Fixing it properly is going to require more effort, but 65c263749e1fbc24fe97a1d0fb198b4fd04023c7 hacks around the issue by ignoring that specific error in that situation.

cuavas avatar Feb 26 '25 17:02 cuavas

Not exactly. Even if the parent chd is made with the latest 0.275, the outcome will be the same.However I tested the latest build and the issue seems to have been temporarily resolved.

crashGG avatar Feb 26 '25 17:02 crashGG