Skip to content

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

Description

@leeewee

When verifying a checksum file (b2sum -c, or cksum -a blake2b --check), uutils derives the BLAKE2b output length from the digest written in the file and passes it straight to the hasher without validating it against the 64-byte maximum. A check line whose digest decodes to more than 64 bytes — for a file that exists — makes blake2b_simd::Params::hash_length fail its assert!(length <= 64) and abort the whole run.

$ mkdir t && cd t
$ echo data > f1                                   # the file named in the check line must exist
$ printf '%s f1\n' "$(printf 'ab%.0s' $(seq 65))" > sums   # 65-byte (130-hex) "digest", filename f1
$ b2sum -c sums
thread 'main' panicked at blake2b_simd-1.0.4/src/lib.rs:239:9:
Bad hash length: 65
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
$ echo $?
134

Any digest length > 64 bytes reproduces it. cksum -a blake2b --check sums takes the same path.

$ cksum -a blake2b --check sums
thread 'main' panicked at blake2b_simd-1.0.4/src/lib.rs:239:9:
Bad hash length: 65
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
$ echo $?
134

GNU b2sum -c rejects the same file gracefully.

$ b2sum -c sums          # GNU coreutils
b2sum: sums: no properly formatted BLAKE2 checksum lines found
$ echo $?
0

Root cause

The --length/-l CLI path is validated (parse_blake_length rejects > 512 bits), but the checksum-file path is not: process_non_algo_based_line sets algo_byte_len = Some(expected_checksum.len()) (src/uucore/src/lib/features/checksum/validate.rs:794) and hands it to SizedAlgoKind::from_unsized, which stores it unchecked (.../checksum/mod.rs:303, Blake2b(l.unwrap_or(..))). Building the digest then calls Blake2b::with_output_bytes(len) (.../features/sum.rs:96) → blake2b_simd hash_length(len), whose assert! panics for len > 64.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions