From 5e4bfff15b23e26c098a998abc0309b7760c808d Mon Sep 17 00:00:00 2001 From: Devel08 Date: Thu, 9 Apr 2026 08:14:50 +0300 Subject: [PATCH 1/4] forbid scientific notation arguments in numfmt --- src/uu/numfmt/src/numfmt.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index 4d5303f5c02..770ff1ef01f 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -47,6 +47,14 @@ fn format_and_write( None => input_line, }; + // Return false if the input is in scientific notation + if line.contains(&101) && line[line.len() - 1] != 69 && line.contains(&69) && line[line.len() - 1] != 101 && line[0] >= 48 && line[0] <= 57 { + let err = NumfmtError::FormattingError(String::from_utf8_lossy(line).to_string()); + let _ = writeln!(stderr(), "numfmt: invalid number: '{err}'"); + + return Ok(false); + } + // In non-abort modes we buffer the formatted output so that on error we // can emit the original line instead. let buffer_output = !matches!(options.invalid, InvalidModes::Abort); From 598b5ebb2215a2d4f38bda4665d3cd3a6b00ed51 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 9 Apr 2026 05:17:17 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/uu/numfmt/src/numfmt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index 770ff1ef01f..2ad4a4c34f3 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -54,7 +54,7 @@ fn format_and_write( return Ok(false); } - + // In non-abort modes we buffer the formatted output so that on error we // can emit the original line instead. let buffer_output = !matches!(options.invalid, InvalidModes::Abort); From 1c70eaaac3fb11411740a8f1ed34832f52dd604b Mon Sep 17 00:00:00 2001 From: Devel08 Date: Thu, 9 Apr 2026 11:22:34 +0300 Subject: [PATCH 3/4] Edit solution of #116555 --- src/uu/numfmt/src/numfmt.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index 2ad4a4c34f3..74be28048d0 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -48,11 +48,16 @@ fn format_and_write( }; // Return false if the input is in scientific notation - if line.contains(&101) && line[line.len() - 1] != 69 && line.contains(&69) && line[line.len() - 1] != 101 && line[0] >= 48 && line[0] <= 57 { - let err = NumfmtError::FormattingError(String::from_utf8_lossy(line).to_string()); - let _ = writeln!(stderr(), "numfmt: invalid number: '{err}'"); - - return Ok(false); + if let Some(pos) = line.iter().position(|&b| b == b'E' || b == b'e') { + if pos < line.len() - 1 { + if line[pos + 1] >= 48 && line[pos + 1] <= 57 { + let errormsg = format!( + "invalid suffix in input: '{}'", + NumfmtError::FormattingError(String::from_utf8_lossy(line).to_string()) + ); + return Err(Box::new(NumfmtError::FormattingError(errormsg))); + } + } } // In non-abort modes we buffer the formatted output so that on error we From d9d4b22e44528e0b8719d78a198dd1d3da3d0f0d Mon Sep 17 00:00:00 2001 From: Devel08 Date: Thu, 9 Apr 2026 11:24:33 +0300 Subject: [PATCH 4/4] add scientific notation test --- tests/by-util/test_numfmt.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/by-util/test_numfmt.rs b/tests/by-util/test_numfmt.rs index 22fa8385d19..a3ea46efcac 100644 --- a/tests/by-util/test_numfmt.rs +++ b/tests/by-util/test_numfmt.rs @@ -1405,7 +1405,6 @@ fn test_large_integer_precision_loss_issue_11654() { // uutils accepts scientific notation (`1e9`, `5e-3`, ...); GNU rejects it // as "invalid suffix in input". #[test] -#[ignore = "GNU compat: see uutils/coreutils#11655"] fn test_scientific_notation_rejected_by_gnu_issue_11655() { new_ucmd!() .arg("1e9")