From 9c4a29d3eef171b743896d6e7168ed6a637a9d4e Mon Sep 17 00:00:00 2001 From: killuazoldyck680 Date: Mon, 15 Jun 2026 20:06:44 +0530 Subject: [PATCH 1/6] fix(true, false): add missing Usage to help templates --- src/uu/arch/locales/en-US.ftl | 4 ++++ src/uu/false/locales/en-US.ftl | 4 ++++ src/uu/false/src/false.rs | 1 + src/uu/true/locales/en-US.ftl | 5 +++++ src/uu/true/src/true.rs | 1 + 5 files changed, 15 insertions(+) diff --git a/src/uu/arch/locales/en-US.ftl b/src/uu/arch/locales/en-US.ftl index 9117053526c..a60316c854e 100644 --- a/src/uu/arch/locales/en-US.ftl +++ b/src/uu/arch/locales/en-US.ftl @@ -4,3 +4,7 @@ cannot-get-system = cannot get system name arch-about = Display machine architecture arch-after-help = Determine architecture name for current machine. arch-usage = arch + +true-usage = true [ignored command-line arguments]... + +false-usage = false [ignored command-line arguments]... diff --git a/src/uu/false/locales/en-US.ftl b/src/uu/false/locales/en-US.ftl index b4bbe787bd9..43e23c6f9d5 100644 --- a/src/uu/false/locales/en-US.ftl +++ b/src/uu/false/locales/en-US.ftl @@ -6,3 +6,7 @@ false-about = Returns false, an unsuccessful exit status. false-help-text = Print help information false-version-text = Print version information +true-usage = + true [ignored command-line arguments]... +false-usage = + false [ignored command-line arguments]... \ No newline at end of file diff --git a/src/uu/false/src/false.rs b/src/uu/false/src/false.rs index d99d8ece4aa..4ef857f84cc 100644 --- a/src/uu/false/src/false.rs +++ b/src/uu/false/src/false.rs @@ -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) diff --git a/src/uu/true/locales/en-US.ftl b/src/uu/true/locales/en-US.ftl index c5806a10d32..f16c4c0cd87 100644 --- a/src/uu/true/locales/en-US.ftl +++ b/src/uu/true/locales/en-US.ftl @@ -6,3 +6,8 @@ true-about = Returns true, a successful exit status. true-help-text = Print help information true-version-text = Print version information + +true-usage = + true [ignored command-line arguments]... +false-usage = + false [ignored command-line arguments]... diff --git a/src/uu/true/src/true.rs b/src/uu/true/src/true.rs index 6e259d17f21..aa0d0a3cfcc 100644 --- a/src/uu/true/src/true.rs +++ b/src/uu/true/src/true.rs @@ -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) From 7bfa734cac124917f953713a167682f87433b6b3 Mon Sep 17 00:00:00 2001 From: killuazoldyck680 Date: Mon, 15 Jun 2026 20:09:05 +0530 Subject: [PATCH 2/6] some changes --- src/uu/arch/locales/en-US.ftl | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/uu/arch/locales/en-US.ftl b/src/uu/arch/locales/en-US.ftl index a60316c854e..e25b34682cb 100644 --- a/src/uu/arch/locales/en-US.ftl +++ b/src/uu/arch/locales/en-US.ftl @@ -5,6 +5,3 @@ arch-about = Display machine architecture arch-after-help = Determine architecture name for current machine. arch-usage = arch -true-usage = true [ignored command-line arguments]... - -false-usage = false [ignored command-line arguments]... From 540d1576822ef6d0904637e0607e144d1ed6ab9d Mon Sep 17 00:00:00 2001 From: killuazoldyck680 Date: Mon, 15 Jun 2026 20:14:21 +0530 Subject: [PATCH 3/6] some more changes --- src/uu/false/locales/en-US.ftl | 7 +++---- src/uu/true/locales/en-US.ftl | 2 -- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/uu/false/locales/en-US.ftl b/src/uu/false/locales/en-US.ftl index 43e23c6f9d5..2a1dfdc190e 100644 --- a/src/uu/false/locales/en-US.ftl +++ b/src/uu/false/locales/en-US.ftl @@ -6,7 +6,6 @@ false-about = Returns false, an unsuccessful exit status. false-help-text = Print help information false-version-text = Print version information -true-usage = - true [ignored command-line arguments]... -false-usage = - false [ignored command-line arguments]... \ No newline at end of file + +false-usage = + false [ignored command-line arguments]... diff --git a/src/uu/true/locales/en-US.ftl b/src/uu/true/locales/en-US.ftl index f16c4c0cd87..25b9996c172 100644 --- a/src/uu/true/locales/en-US.ftl +++ b/src/uu/true/locales/en-US.ftl @@ -9,5 +9,3 @@ true-version-text = Print version information true-usage = true [ignored command-line arguments]... -false-usage = - false [ignored command-line arguments]... From 9a72a672de3b5d17382ddff80d34d39f6bfdf93e Mon Sep 17 00:00:00 2001 From: killuazoldyck680 Date: Tue, 16 Jun 2026 20:16:18 +0530 Subject: [PATCH 4/6] cksum: fix OOM panic --- src/uu/cksum/src/cksum.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index 9af2f6f00ff..7eb85dc3957 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -52,7 +52,7 @@ fn maybe_sanitize_length( match (algo_cli, input_length) { // No provided length is not a problem so far. (_, None) => Ok(None), - + // For SHA2 and SHA3, if a length is provided, ensure it is correct. (Some(algo @ (AlgoKind::Sha2 | AlgoKind::Sha3)), Some(s_len)) => { sanitize_sha2_sha3_length_str(algo, s_len).map(Some) @@ -64,7 +64,13 @@ fn maybe_sanitize_length( // will have its extra bits set to zero. (Some(AlgoKind::Shake128 | AlgoKind::Shake256), Some(len)) => match len.parse::() { Ok(0) => Ok(None), - Ok(l) => Ok(Some(HashLength::from_bits(l))), + Ok(l) => { + if l > u32::MAX as usize { + Err(ChecksumError::InvalidLength(len.into()).into()) + } else { + Ok(Some(HashLength::from_bits(l))) + } + } Err(_) => Err(ChecksumError::InvalidLength(len.into()).into()), }, From b17b60585397df6ffb940619fe7c0a32956fcedc Mon Sep 17 00:00:00 2001 From: killuazoldyck680 Date: Tue, 16 Jun 2026 22:40:09 +0530 Subject: [PATCH 5/6] fix(cksum): handle memory exhaustion gracefully for shake algorithms --- src/uu/cksum/src/cksum.rs | 22 ++++++++++++++++------ src/uu/false/locales/en-US.ftl | 2 -- src/uu/true/locales/en-US.ftl | 2 -- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index 7eb85dc3957..cf99cb81300 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -52,7 +52,7 @@ fn maybe_sanitize_length( match (algo_cli, input_length) { // No provided length is not a problem so far. (_, None) => Ok(None), - + // For SHA2 and SHA3, if a length is provided, ensure it is correct. (Some(algo @ (AlgoKind::Sha2 | AlgoKind::Sha3)), Some(s_len)) => { sanitize_sha2_sha3_length_str(algo, s_len).map(Some) @@ -65,11 +65,22 @@ fn maybe_sanitize_length( (Some(AlgoKind::Shake128 | AlgoKind::Shake256), Some(len)) => match len.parse::() { Ok(0) => Ok(None), Ok(l) => { - if l > u32::MAX as usize { - Err(ChecksumError::InvalidLength(len.into()).into()) - } else { - Ok(Some(HashLength::from_bits(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 = 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()), }, @@ -121,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) } diff --git a/src/uu/false/locales/en-US.ftl b/src/uu/false/locales/en-US.ftl index 2a1dfdc190e..6a4695edbef 100644 --- a/src/uu/false/locales/en-US.ftl +++ b/src/uu/false/locales/en-US.ftl @@ -7,5 +7,3 @@ false-about = Returns false, an unsuccessful exit status. false-help-text = Print help information false-version-text = Print version information -false-usage = - false [ignored command-line arguments]... diff --git a/src/uu/true/locales/en-US.ftl b/src/uu/true/locales/en-US.ftl index 25b9996c172..1f9554dbbb1 100644 --- a/src/uu/true/locales/en-US.ftl +++ b/src/uu/true/locales/en-US.ftl @@ -7,5 +7,3 @@ true-about = Returns true, a successful exit status. true-help-text = Print help information true-version-text = Print version information -true-usage = - true [ignored command-line arguments]... From 14915863bbdcef2683f024d81d429340bc4ada5c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 16 Jun 2026 20:50:49 +0000 Subject: [PATCH 6/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/uu/arch/locales/en-US.ftl | 1 - src/uu/false/locales/en-US.ftl | 1 - src/uu/true/locales/en-US.ftl | 1 - 3 files changed, 3 deletions(-) diff --git a/src/uu/arch/locales/en-US.ftl b/src/uu/arch/locales/en-US.ftl index e25b34682cb..9117053526c 100644 --- a/src/uu/arch/locales/en-US.ftl +++ b/src/uu/arch/locales/en-US.ftl @@ -4,4 +4,3 @@ cannot-get-system = cannot get system name arch-about = Display machine architecture arch-after-help = Determine architecture name for current machine. arch-usage = arch - diff --git a/src/uu/false/locales/en-US.ftl b/src/uu/false/locales/en-US.ftl index 6a4695edbef..b4bbe787bd9 100644 --- a/src/uu/false/locales/en-US.ftl +++ b/src/uu/false/locales/en-US.ftl @@ -6,4 +6,3 @@ false-about = Returns false, an unsuccessful exit status. false-help-text = Print help information false-version-text = Print version information - diff --git a/src/uu/true/locales/en-US.ftl b/src/uu/true/locales/en-US.ftl index 1f9554dbbb1..c5806a10d32 100644 --- a/src/uu/true/locales/en-US.ftl +++ b/src/uu/true/locales/en-US.ftl @@ -6,4 +6,3 @@ true-about = Returns true, a successful exit status. true-help-text = Print help information true-version-text = Print version information -