Skip to content

squashfs: handle images with no fragment or xattr table#413

Open
maximilize wants to merge 1 commit into
diskfs:masterfrom
maximilize:squashfs-absent-tables
Open

squashfs: handle images with no fragment or xattr table#413
maximilize wants to merge 1 commit into
diskfs:masterfrom
maximilize:squashfs-absent-tables

Conversation

@maximilize

Copy link
Copy Markdown

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):

  • No fragment table (fragmentCount == 0): readFragmentTable reads unconditionally, but fragmentTableStart holds the 0xffffffffffffffff "not present" sentinel, so ReadAt seeks to offset -1 and fails with error reading fragment table index: invalid seek position.
  • No xattr table (NO_XATTRS flag): directoryEntryFromInode calls fs.xattrs.find(...) when an inode advertises an xattr index, but fs.xattrs is nil, 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):

  • skip reading the fragment table when fragmentCount == 0;
  • skip the xattr lookup when fs.xattrs == nil.

Tests

Added two internal regression tests (TestReadFragmentTableNoFragments and TestDirectoryEntryFromInodeNilXattrTable), both failing before / passing after. Full filesystem/squashfs suite passes and go vet is clean.

Verified end-to-end through rclone's archive backend (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.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant