Skip to content

cksum: do not abort on an over-length BLAKE2b digest in a check file - #14508

Open
Dijaa wants to merge 1 commit into
uutils:mainfrom
Dijaa:blake2b-check-overlong-digest
Open

cksum: do not abort on an over-length BLAKE2b digest in a check file#14508
Dijaa wants to merge 1 commit into
uutils:mainfrom
Dijaa:blake2b-check-overlong-digest

Conversation

@Dijaa

@Dijaa Dijaa commented Sep 11, 2026

Copy link
Copy Markdown

A check line whose digest is longer than the 64 bytes BLAKE2b allows takes
down the whole run instead of being skipped:

$ echo data > f1
$ printf '%s f1\n' "$(printf 'ab%.0s' $(seq 65))" > sums # 65-byte digest
$ ./target/release/coreutils b2sum -c sums
thread 'main' panicked at blake2b_simd-1.0.5/src/lib.rs:241:9:
Bad hash length: 65
Aborted (core dumped)
$ echo $?
134

GNU coreutils 9.4 skips the line and says so:

$ b2sum -c sums
b2sum: sums: no properly formatted checksum lines found
$ echo $?
1

cksum -a blake2b --check goes down the same path.

The --length flag and tagged lines (BLAKE2b-520 (f) = ...) both run their
length through parse_blake_length, which rejects anything above 512 bits.
The untagged path does not: process_non_algo_based_line takes the length
straight from the digest it just decoded and hands it on, so
Blake2b::with_output_bytes reaches blake2b_simd's hash_length with 65
and trips its assertion.

This sends that inferred length through parse_blake_length too, and turns a
rejected length into LineCheckError::ImproperlyFormatted — the same "skip
the line" path GNU takes. HashLength::from_bytes had no caller left
afterwards, so it goes.

Worth noting for anyone reproducing it: the exit code depends on the profile.
In a debug build our own debug_assert! in Blake2b::with_output_bytes fires
first and you get 101; in release it is compiled out, blake2b_simd aborts,
and panic = "abort" turns that into SIGABRT, 134. Same bug either way.

Fixes #14487

When verifying a checksum file, the BLAKE2b output length was inferred
from the digest found in the file and handed to the hasher unchecked. A
digest longer than the 64 bytes BLAKE2b maximum made blake2b_simd fail
its own length assertion and abort the process, instead of the line
being reported as malformed.

Route that inferred length through parse_blake_length, like the --length
and tagged-line paths already do, and treat a rejected length as an
improperly formatted line. This matches GNU, which skips such a line and
exits 1 with "no properly formatted checksum lines found".

HashLength::from_bytes loses its last caller with this change, so drop
it.

Fixes uutils#14487
Copilot AI lite review requested due to automatic review settings September 11, 2026 15:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The supplied review found no unresolved approval blockers.

Pull request overview

Fixes checksum validation so over-length BLAKE2b digests are rejected as malformed instead of aborting.

Changes:

  • Validate inferred BLAKE2b digest lengths.
  • Remove the unused HashLength::from_bytes helper.
  • Add regression coverage.
File summaries
File Description
tests/by-util/test_cksum.rs Adds oversized BLAKE2b digest coverage.
src/uucore/src/lib/features/checksum/validate.rs Validates inferred digest lengths safely.
src/uucore/src/lib/features/checksum/mod.rs Removes the unused conversion helper.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/cut/cut-huge-range is now passing!
Congrats! The gnu test tests/rm/many-dir-entries-vs-OOM is now passing!
Note: The gnu test tests/misc/write-errors was skipped on 'main' but is now failing.

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.

b2sum/cksum --check: an over-length BLAKE2b digest in the checksum file aborts the process (exit 134/141)

2 participants