CalebQ42 / squashfs

A library to interact with Squashfs archives. Currently only has support for reading, but writing archives will probably come eventually.
MIT License
27 stars 9 forks source link

Error decompressing files with lots of NULLs #24

Closed ncw closed 1 year ago

ncw commented 1 year ago

Summary: A file with 321 NULLs unpacks as 128k of NULLs.

I've made a small test archive - unzip the bug.sqsh to demonstrate:

bug.sqfs.zip

go install github.com/CalebQ42/squashfs/...@main
go-unsquashfs bug.sqfs bug-out-go-unsquashfs
unsquashfs -d bug-out-unsquashfs bug.sqfs

Comparing the two extractions

$ ls -l bug-out-go-unsquashfs
total 128
-rw-rw-r-- 1 ncw ncw 131072 Aug 11 17:37 file2

vs

$ ls -l bug-out-unsquashfs
total 4
-rw-rw-r-- 1 ncw ncw 321 Sep  7  2020 file2

file2 is 321 bytes of NULLs where it seems to have unpacked as 131072 bytes (so one block) of NULLs with go-unsquashfs

bug.sqsh was made like this, so with default options for mksquashfs.

mksquashfs source/ bug.sqfs
CalebQ42 commented 1 year ago

Fixed with v0.8.2.

In theory mksquashfs should only have sparse blocks (only zero blocks) if they are a full blocksize, but evidently that isn't necessarily true. I simply added a check that if it is asking for a sparse block on a file that is less then a block in size then it only creates a file of the file size. It's possible that this isn't a clean fix since it seems that mksquashfs is doing things with sparse files that the documentation I use doesn't cover. Particularly it's possible that a block that's less then blocksize at the end of a larger file (such as if never fragment is specified) that's sparse could have a similar issue. That being said, that would take a bit more work then a quick fix so I'll worry about that when/if it shows up.

ncw commented 1 year ago

I can confirm this fixes my problem - thank you for a super quick fix :-)