Skip to content
20 changes: 18 additions & 2 deletions src/uu/cksum/src/cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,24 @@ fn maybe_sanitize_length(
// will have its extra bits set to zero.
(Some(AlgoKind::Shake128 | AlgoKind::Shake256), Some(len)) => match len.parse::<usize>() {
Ok(0) => Ok(None),
Ok(l) => Ok(Some(HashLength::from_bits(l))),
Ok(l) => {
const BITS_PER_BYTE: usize = 8;
const OOM_SAFETY_CUSHION_BYTES: usize = 65536;
let bytes_needed = l.div_ceil(BITS_PER_BYTE);

let mut test_buffer: Vec<u8> = Vec::new();

let safety_cushion = bytes_needed.saturating_add(OOM_SAFETY_CUSHION_BYTES);

if test_buffer.try_reserve(safety_cushion).is_err() {
return Err(uucore::error::USimpleError::new(
1,
translate!("memory exhausted"),
));
}

Ok(Some(HashLength::from_bits(l)))
}
Err(_) => Err(ChecksumError::InvalidLength(len.into()).into()),
},

Expand Down Expand Up @@ -115,7 +132,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
if matches.get_flag(options::DEBUG) {
print_cpu_debug_info();
}

checksum_main(algo_cli, length, matches, output_format)
}

Expand Down
1 change: 1 addition & 0 deletions src/uu/false/src/false.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub fn uu_app() -> Command {
.version(crate_version!())
.help_template(uucore::localized_help_template("false"))
.about(translate!("false-about"))
.override_usage(translate!("false-usage"))
// We provide our own help and version options, to ensure maximum compatibility with GNU.
.disable_help_flag(true)
.disable_version_flag(true)
Expand Down
1 change: 1 addition & 0 deletions src/uu/true/src/true.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub fn uu_app() -> Command {
.version(crate_version!())
.help_template(uucore::localized_help_template("true"))
.about(translate!("true-about"))
.override_usage(translate!("true-usage"))
// We provide our own help and version options, to ensure maximum compatibility with GNU.
.disable_help_flag(true)
.disable_version_flag(true)
Expand Down
Loading