Skip to content

checksum: do not let improperly formatted lines select the line format - #15880

Open
fixfon wants to merge 1 commit into
uutils:mainfrom
fixfon:fix/15770-checksum-format-cache
Open

fixfon wants to merge 1 commit into
uutils:mainfrom
fixfon:fix/15770-checksum-format-cache

Conversation

@fixfon

@fixfon fixfon commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #15770

LineInfo::parse stored the detected line format in cached_line_format as soon as a line matched a parser, before the digest was validated. A free-text line such as 2024 release matched the single-space parser, was then rejected as improperly formatted, but had already made single-space the format for the rest of the file. Every following <digest> name line was read as the file name (with a leading space), so the files that were actually listed were never opened. With a file named a next to a tampered a, md5sum --check printed ' a': OK and exited 0. A line like Checksums for release did the same the other way round and dropped valid single-space lines.

process_checksum_line now parses into a local copy of the cache and writes it back only when the line is not improperly formatted. LineInfo::parse and its signature are unchanged. Lines that are well formed but fail later (DigestMismatch, missing or unreadable file) still set the format, as before.

Tests: three unit tests in validate.rs and one md5sum integration test, appended at the end of test_md5sum.rs. The two format-selection unit tests and the integration test fail on current main and pass with this change. The third unit test is a guard for the unchanged behaviour. I also ran the issue's example with a build from main and one with this change: before, md5sum --check reported the tampered files as OK (exit 0); after, it reports a: FAILED, c: FAILED and exits 1.

Ran locally: cargo fmt --all -- --check, cargo clippy --all-targets -- -D warnings at the workspace root, cargo test -p uucore --features checksum checksum::validate, and the test_md5sum, test_sha256sum and test_cksum integration tests (448 passed). Tested on macOS only; spell-check was not run.

The format was cached as soon as a line matched a parser syntactically,
before its digest was validated. A free-text line such as "2024 release"
could therefore switch how the following lines were read, so the listed
files were never opened. The format is now recorded only for lines that are
not improperly formatted.

Fixes uutils#15770

This branch has not been deployed

No deployments
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.

checksum: malformed line caches single-space format, tampered files pass

1 participant