squashfs: handle images with no fragment or xattr table#413
Open
maximilize wants to merge 1 commit into
Open
Conversation
squashfs-tools-ng writes valid images that omit the fragment table (e.g. a single empty directory, or with -no-tail-packing) and/or the xattr table (the NO_XATTRS superblock flag). The reader mishandled both: - readFragmentTable read the table even when fragmentCount == 0. In that case fragmentTableStart holds the 0xffff... "not present" sentinel, so the ReadAt seeks to offset -1 and fails with "invalid seek position". - directoryEntryFromInode dereferenced fs.xattrs when an inode advertised an xattr index while the image had no xattr table (fs.xattrs == nil), causing a nil-pointer panic in (*xAttrTable).find. Guard both: return early for an absent fragment table, and skip the xattr lookup when the table is nil. Adds regression tests for both paths. Surfaced via rclone (rclone/rclone#9004), which uses this reader for its archive backend; both a single-empty-dir image and a real squashfs-tools-ng image now list correctly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: maximilize <max@maxmax.ch>
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.
Problem
The squashfs reader fails on valid images written by squashfs-tools-ng that omit optional tables. Two independent failures, both reproducible with a minimal image (
gensquashfs -D <empty-dir> out.sqfs):fragmentCount == 0):readFragmentTablereads unconditionally, butfragmentTableStartholds the0xffffffffffffffff"not present" sentinel, soReadAtseeks to offset-1and fails witherror reading fragment table index: invalid seek position.NO_XATTRSflag):directoryEntryFromInodecallsfs.xattrs.find(...)when an inode advertises an xattr index, butfs.xattrsisnil, causing a nil-pointer panic in(*xAttrTable).find(xattr.go:46).Fix
Two guards, mirroring the "absent optional table" handling already done when the superblock is parsed (
!s.noXattrs && s.xattrTableStart != 0xffffffffffffffff):fragmentCount == 0;fs.xattrs == nil.Tests
Added two internal regression tests (
TestReadFragmentTableNoFragmentsandTestDirectoryEntryFromInodeNilXattrTable), both failing before / passing after. Fullfilesystem/squashfssuite passes andgo vetis clean.Verified end-to-end through rclone's
archivebackend (which uses this reader): the two images from rclone/rclone#9004 that previously errored / panicked (a single empty directory, and a real squashfs-tools-ng Windows image) now list correctly.