uucore: reject over-length BLAKE2b digests when checking (#14508) · uutils/coreutils@ebcdac1 · GitHub
Skip to content

Commit ebcdac1

Browse files
authored
uucore: reject over-length BLAKE2b digests when checking (#14508)
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 #14487
1 parent 319f49f commit ebcdac1

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

‎src/uucore/src/lib/features/checksum/mod.rs‎

Lines changed: 0 additions & 6 deletions

‎src/uucore/src/lib/features/checksum/validate.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,12 @@ fn process_non_algo_based_line(
791791
// bits except when dealing with blake2b, sha2 and sha3, where we will
792792
// detect the length.
793793
let algo_len = match cli_algo_kind {
794-
ak::Blake2b | ak::Blake3 => Some(HashLength::from_bytes(expected_checksum.len())),
794+
// An over-length digest makes this a malformed line for GNU, not a
795+
// fatal error.
796+
algo @ (ak::Blake2b | ak::Blake3) => Some(
797+
parse_blake_length(algo, BlakeLength::Int(expected_checksum.len() * 8))
798+
.map_err(|_| LineCheckError::ImproperlyFormatted)?,
799+
),
795800
ak::Sha2 | ak::Sha3 => {
796801
// multiplication by 8 to get the number of bits
797802
Some(

‎tests/by-util/test_cksum.rs‎

Lines changed: 14 additions & 0 deletions

0 commit comments

Comments
 (0)