Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/uucore/src/lib/features/checksum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,6 @@ pub struct HashLength {
}

impl HashLength {
#[must_use]
#[inline]
pub(crate) fn from_bytes(n: usize) -> Self {
Self { bit_len: n * 8 }
}

#[must_use]
#[inline]
pub fn from_bits(n: usize) -> Self {
Expand Down
7 changes: 6 additions & 1 deletion src/uucore/src/lib/features/checksum/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,12 @@ fn process_non_algo_based_line(
// bits except when dealing with blake2b, sha2 and sha3, where we will
// detect the length.
let algo_len = match cli_algo_kind {
ak::Blake2b | ak::Blake3 => Some(HashLength::from_bytes(expected_checksum.len())),
// An over-length digest makes this a malformed line for GNU, not a
// fatal error.
algo @ (ak::Blake2b | ak::Blake3) => Some(
parse_blake_length(algo, BlakeLength::Int(expected_checksum.len() * 8))
.map_err(|_| LineCheckError::ImproperlyFormatted)?,
),
ak::Sha2 | ak::Sha3 => {
// multiplication by 8 to get the number of bits
Some(
Expand Down
14 changes: 14 additions & 0 deletions tests/by-util/test_cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,20 @@ fn test_md5_bits() {
.stderr_contains("f: no properly formatted checksum lines found");
}

#[test]
fn test_blake2b_check_digest_too_long() {
let (at, mut ucmd) = at_and_ucmd!();
// The referenced file must exist: the digest length is only used once the
// line is accepted and the file is about to be hashed.
at.write("f1", "content\n");
// 65 bytes, above the 64 bytes BLAKE2b maximum.
at.write("sums", &format!("{} f1\n", "a".repeat(130)));

ucmd.args(&["-a", "blake2b", "-c", "sums"])
.fails_with_code(1)
.stderr_contains("sums: no properly formatted checksum lines found");
}

#[test]
fn test_blake2b_bits() {
let (at, mut ucmd) = at_and_ucmd!();
Expand Down
Loading