squashfs: fix inode block references when metadata is compressed (#360)#377
Merged
deitch merged 2 commits intodiskfs:masterfrom Apr 16, 2026
Merged
squashfs: fix inode block references when metadata is compressed (#360)#377deitch merged 2 commits intodiskfs:masterfrom
deitch merged 2 commits intodiskfs:masterfrom
Conversation
…kfs#360) updateInodeLocations pre-computed each inode's metadata-block byte offset as `logicalBlock * (metadataBlockSize + 2)` = `logicalBlock * 8194`, which assumes every compressed metadata block is exactly 8194 bytes on disk. That's only true when compression is effectively off. With real gzip compression metadata blocks are typically much smaller, so directory entries and the superblock root-inode ref pointed past the real block positions. Readers then failed with "could not read directory entries" or "failed to read inode X:Y" for every file whose inode was not in block 0. The bug reproduces without any "large" file — it just needs enough inodes to span a metadata block boundary AND effective compression. A single large file triggers it too because its extendedFile inode carries one block-size entry per data block (a 1 GB file at 128 KB blocksize needs ~32 KB of inode, spanning 4 metadata blocks by itself). Fix: store a logical block index in updateInodeLocations, then have writeInodes track the actual on-disk byte offset of each metadata block as it writes them. After writeInodes returns, translateInodeLocations rewrites every inodeLocation.block and every directory entry's startBlock from logical index to real byte offset, before the directory table (which embeds those references) is written. There's a matching TODO at finalize.go:274 noting "blockPosition calculations appear to be off" — this fixes that. The reproducer test TestFinalizeInodesAcrossMetadataBlocks was added as a standalone failing test in a preceding PR; it passes after this fix.
- Use fmt.Fprintf instead of fh.Write([]byte(fmt.Sprintf(...))) - Combine consecutive same-type parameters in translateInodeLocations
Contributor
Author
|
Fixes #360 |
This was referenced Apr 16, 2026
deitch
approved these changes
Apr 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
updateInodeLocations pre-computed each inode's metadata-block byte offset as
logicalBlock * (metadataBlockSize + 2)=logicalBlock * 8194, which assumes every compressed metadata block is exactly 8194 bytes on disk. That's only true when compression is effectively off. With real gzip compression metadata blocks are typically much smaller, so directory entries and the superblock root-inode ref pointed past the real block positions. Readers then failed with "could not read directory entries" or "failed to read inode X:Y" for every file whose inode was not in block 0.The bug reproduces without any "large" file — it just needs enough inodes to span a metadata block boundary AND effective compression. A single large file triggers it too because its extendedFile inode carries one block-size entry per data block (a 1 GB file at 128 KB blocksize needs ~32 KB of inode, spanning 4 metadata blocks by itself).
Fix: store a logical block index in updateInodeLocations, then have writeInodes track the actual on-disk byte offset of each metadata block as it writes them. After writeInodes returns, translateInodeLocations rewrites every inodeLocation.block and every directory entry's startBlock from logical index to real byte offset, before the directory table (which embeds those references) is written.
There's a matching TODO at finalize.go:274 noting "blockPosition calculations appear to be off" — this fixes that.
The reproducer test TestFinalizeInodesAcrossMetadataBlocks was added as a standalone failing test in a preceding PR; it passes after this fix.