AgentD / squashfs-tools-ng

A new set of tools and libraries for working with SquashFS images
Other
194 stars 30 forks source link

Incompatibility between squashfs-tools-ng and squashfs-tools #104

Closed m94mni closed 2 years ago

m94mni commented 2 years ago

I reported this here:

https://github.com/plougher/squashfs-tools/issues/168

But I'm not sure if perhaps the issue is in this package. In short:

  1. Create an image containing a single zero-byte file using tar2sqfs (from this package).
  2. Try to unpack it using unsquashfs from the squashfs-tools package.
  3. Get error, per bug above.

Mounting the image works ok though.

m94mni commented 2 years ago

rdsquashfs can read the image, so I suspect unsquashfs.

AgentD commented 2 years ago

Hi @m94mni ,

this is related to issue #85.

To summarize the underlying problem: SquashFS stores the on-disk size of a directory redundantly: Every entry has it's own size field and the inode stores the total sum. However, the sum is stored off-by-3, and the kernel uses that magic offset to fudge in the entries for . and .., but in the actual reading loop uses the individual entry size. This means, that the kernel implementation works perfectly fine if the exact size is mistakenly stored in the inode. A directory with at least 1 entry will always be >3 bytes, because meta data is also accounted for.

Squashfs-tools-ng started out by reverse engineering the format (none of this was documented before) and primarily testing against the kernel implementation. While the kernel side worked, squashfs-tools and 7zip (see #85) rely on the value in the inode, so they could not unpack such archives generated by squashfs-tools-ng.

A fix is included in most recent 1.1.3 release and has been backported to the 1.0.x branch, where it is part of the 1.0.6 release.

m94mni commented 2 years ago

Thanks for the context, newer versions do work!