Skip to content

fix(inspect): correct ext4 filesystem misdetection in image inspect#484

Open
arodage wants to merge 3 commits intomainfrom
fix/inspect-ext4-fs-detection
Open

fix(inspect): correct ext4 filesystem misdetection in image inspect#484
arodage wants to merge 3 commits intomainfrom
fix/inspect-ext4-fs-detection

Conversation

@arodage
Copy link
Contributor

@arodage arodage commented Mar 16, 2026

Merge Checklist

All boxes should be checked before merging the PR

  • The changes in the PR have been built and tested
  • Documentation has been updated to reflect the changes (or no doc update needed)
  • Ready to merge

Description

inspect --extract-sbom to fail with "invalid boot sector signature" on valid raw images with ext4 rootfs partitions.

Root cause: enrichFilesystemFromRaw() only ran raw magic byte sniffing when the filesystem type was empty or "unknown". When go-diskfs already set it to "vfat" (incorrectly), the sniffing was skipped and the code tried to read the partition as FAT — which failed.

Fix: Always cross-check the go-diskfs classification against raw magic bytes (ext4 superblock magic 0xEF53 at offset 1024+56). When they disagree and are not in the same filesystem family, trust the raw magic bytes and add an informational note.

Changes:

  • enrichFilesystemFromRaw(): always sniff raw magic, correct misclassifications
  • Added isExtLike() helper for ext filesystem family detection
  • Added isSameFSFamily() helper for comparing filesystem families
  • Added unit tests for all new helpers and the correction behavior

No documentation updates needed, this is a bugfix to existing inspect functionality.

Any Newly Introduced Dependencies

None.

How Has This Been Tested?

  1. Unit tests: Added TestIsSameFSFamily, TestIsExtLike, TestEnrichFilesystemFromRaw_CorrectsMisclassifiedExt4, and TestEnrichFilesystemFromRaw_KeepsCorrectVFAT. All pass.
  2. Full package test suite: go test ./internal/image/imageinspect/... passes with no regressions.
  3. Manual verification on real image: Tested on ubuntu24-x86_64-minimal-raw image:
    • Before fix: inspect showed partition 2 as vfat, --extract-sbom failed
    • After fix: inspect correctly shows partition 2 as ext4 with note "filesystem type corrected from vfat to ext4 (raw magic)", and --extract-sbom successfully extracts the 209-package SPDX SBOM

arodage added 2 commits March 16, 2026 18:39
The go-diskfs library can misclassify ext4 partitions as vfat when the
partition data happens to contain 0x55AA at offset 510. This caused
'inspect --extract-sbom' to fail with 'invalid boot sector signature'
on valid raw images.

Fix: always cross-check the diskfs filesystem classification against raw
magic bytes (ext4 superblock magic 0xEF53). When they disagree, trust
the raw magic and add an informational note. Added isExtLike() and
isSameFSFamily() helpers for filesystem family comparison.

Verified on a real ubuntu24-x86_64-minimal-raw image where partition 2
(rootfs) was misidentified as vfat. After the fix, inspect correctly
detects ext4 and successfully extracts the embedded SPDX SBOM.
- isSameFSFamily: normalize inputs with TrimSpace before final
  EqualFold fallback comparison for consistent whitespace handling
- TestEnrichFilesystemFromRaw_KeepsCorrectVFAT: check error return
  from enrichFilesystemFromRaw (errcheck compliance) and populate
  minimal valid FAT32 BPB fields for a realistic test buffer
- TestIsSameFSFamily: add whitespace normalization test case
@arodage arodage requested a review from a team as a code owner March 16, 2026 22:48
Copilot AI review requested due to automatic review settings March 16, 2026 22:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes inspect --extract-sbom failures caused by go-diskfs occasionally misclassifying ext4 partitions as VFAT by adding a raw-magic cross-check and correcting the filesystem type when the two detections disagree.

Changes:

  • Always sniff filesystem type from raw partition bytes in enrichFilesystemFromRaw() and correct misclassifications (with an informational note).
  • Add filesystem-family helpers (isExtLike, isSameFSFamily) to avoid “corrections” across closely related filesystem labels.
  • Add unit tests for the new helpers and for ext4-misclassified-as-vfat correction behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
internal/image/imageinspect/fs_inspect.go Always performs raw magic sniffing and uses helper(s) to decide when to override go-diskfs’s filesystem type.
internal/image/imageinspect/imageinspect_core_test.go Adds tests for the new helpers and verifies correction behavior for misclassified ext4 partitions.

You can also share your feedback on Copilot code review. Take the survey.

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.

2 participants