fix(inspect): correct ext4 filesystem misdetection in image inspect#484
Open
fix(inspect): correct ext4 filesystem misdetection in image inspect#484
Conversation
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
Contributor
There was a problem hiding this comment.
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.
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.
Merge Checklist
All boxes should be checked before merging the PR
Description
inspect --extract-sbomto 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". Whengo-diskfsalready 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-diskfsclassification against raw magic bytes (ext4 superblock magic0xEF53at 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 misclassificationsisExtLike()helper for ext filesystem family detectionisSameFSFamily()helper for comparing filesystem familiesNo documentation updates needed, this is a bugfix to existing inspect functionality.
Any Newly Introduced Dependencies
None.
How Has This Been Tested?
TestIsSameFSFamily,TestIsExtLike,TestEnrichFilesystemFromRaw_CorrectsMisclassifiedExt4, andTestEnrichFilesystemFromRaw_KeepsCorrectVFAT. All pass.go test ./internal/image/imageinspect/...passes with no regressions.ubuntu24-x86_64-minimal-rawimage:inspectshowed partition 2 asvfat,--extract-sbomfailedinspectcorrectly shows partition 2 asext4with note "filesystem type corrected from vfat to ext4 (raw magic)", and--extract-sbomsuccessfully extracts the 209-package SPDX SBOM