Repository navigation
Be more permissive of bad/missing UBI checksums - #974
Draft
BenSeverson wants to merge 1 commit into
Draft
BenSeverson wants to merge 1 commit into
BenSeverson wants to merge 1 commit into
Conversation
UBI/UBIFS images recovered from flash dumps frequently have corrupt or zeroed header checksums, and previously any such image was rejected outright: no signature was reported, so no extraction was attempted. The three UBI header parsers now treat the CRC as advisory and report whether it validated. Because the checksum can no longer vouch for the rest of the header, additional structural checks are applied when, and only when, the CRC is bad or missing, so images with valid checksums parse exactly as they did before: - superblock: sane leb_size and leb_count - EC header: NULL padding, bounded header offsets - volume header: known volume, copy and compatibility types Images that fail their checksums are reported at medium confidence with "invalid header checksum" in the description. A UBIFS image whose reported size runs past EOF is now reported with an unknown size rather than being discarded by the end-of-file sanity check, so a truncated image can still be extracted. Finally, both ubireader utilities are invoked with -i and -w, so that blocks with bad header checksums are included in the extraction and bad block reads are not fatal. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
UBI/UBIFS images recovered from flash dumps frequently have corrupt or zeroed
header checksums. Previously any such image was rejected outright by the header
parsers, so no signature was reported and no extraction was attempted.
Signature / structure parsing
The three UBI header parsers now treat the CRC as advisory and report whether it
validated, via a new
crc_validfield. Because the checksum can no longer vouchfor the rest of the header, additional structural checks are applied when, and
only when, the CRC is bad or missing — images with valid checksums parse exactly
as they did before:
leb_size1KB-16MB,leb_count1-1Mcopy_flag<= 1,compat_type<= 5Images that fail their checksums are reported at
CONFIDENCE_MEDIUMwith", invalid header checksum" appended to the description.
ubi_parseralso trackswhether any of the per-block volume headers failed its CRC, not just the erase
count header. Sizes are computed with
saturating_mul, since unvalidated LEBfields now feed the multiply.
A UBIFS image whose computed size runs past EOF is reported with an unknown size
and "(truncated)", rather than being discarded by the end-of-file sanity check in
Binwalk::scan, so a partial image can still be extracted. This part isindependent of the checksum work and can be dropped if unwanted.
Extraction
Both ubireader utilities are now invoked with
-i(ignore block header errors)and
-w(warn-only on bad block reads). These gate exactly the CRC andread-error paths in
ubi/block/__init__.pyandubifs/walk.pyin ubi_reader0.8.15.
-f(u-bootimage_seq == 0fix) was deliberately left out, since thataddresses a sequence number mismatch rather than a checksum.
Testing
Synthetic UBI and UBIFS images were built with correct CRCs and again with
corrupted ones:
are detected and flagged. Output for the valid images is byte-identical to
before.
count magic and the UBI volume magic, followed by random bytes, produced zero
detections.
cargo fmtclean;cargo clippy --all-targetsreports only the twopre-existing
romfs.rswarnings.No test fixtures were added, since the repo has no UBI inputs and CI does not
install ubi_reader, so an extraction test would fail there. Extraction itself is
therefore unverified - ubi_reader was not installed in the dev environment, and
the flags' behavior was confirmed by reading its source rather than by running it.
🤖 Generated with Claude Code