Skip to content

split: avoid overflow on a suffix start with a huge number of chunks - #14092

Merged
sylvestre merged 1 commit into
uutils:mainfrom
SAY-5:split-fix-suffix-start-overflow
Nov 29, 2026
Merged

sylvestre merged 1 commit into
uutils:mainfrom
SAY-5:split-fix-suffix-start-overflow

Conversation

@SAY-5

@SAY-5 SAY-5 commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #13749.

#15649 already rejects a start value that does not fit the suffix length, so this is now down to the other case from the issue: with a huge chunk count and a start below it, start as u64 + chunks still overflows (split -n r/1/18446744073709551615 --numeric-suffixes=5 panics with attempt to add with overflow on main). This uses saturating_add there, and the output then matches GNU.

@codspeed

codspeed Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by ×3.3

1 warning

⚠️ 5 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚡ 2 improved benchmarks
✅ 8 untouched benchmarks
⏩ 466 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ CPU Simulation split_lines 14.4 ms 4.4 ms ×3.3
⚡ CPU Simulation split_numeric_suffix 14.6 ms 4.6 ms ×3.2

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing SAY-5:split-fix-suffix-start-overflow (4cb42bd) with main (b5223da)2

Open in CodSpeed

Footnotes

  1. 466 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (408b976) during the generation of this report, so b5223da was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@github-actions

github-actions Bot commented Aug 23, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/id/smack is no longer failing!
Congrats! The gnu test tests/mkdir/smack-no-root is no longer failing!
Congrats! The gnu test tests/mkdir/smack-root is no longer failing!
Congrats! The gnu test tests/df/skip-rootfs is now passing!

@sylvestre

Copy link
Copy Markdown
Contributor

some jobs are failing, could you please have a look? thanks

@sylvestre sylvestre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need more work

@SAY-5

SAY-5 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

the failure was a rustfmt diff in the new overflow test, my .args line was over the width limit. just pushed the reformat. the i686/windows build jobs hit cache 429s so they should come back green on the rerun.

Comment thread tests/by-util/test_split.rs Outdated
// A suffix start value near `u64::MAX` must not overflow the auto-width
// calculation; it should be reported as an error rather than aborting.
#[test]
fn test_numeric_suffix_start_overflow() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start is a usize, so on 32-bit this value won't parse and the error will be different. please gate these tests with #[cfg(target_pointer_width = "64")] like the others in this file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gated both tests with #[cfg(target_pointer_width = "64")] in e22f5e1.

Comment thread tests/by-util/test_split.rs Outdated
"/dev/null",
])
.fails()
.stderr_contains("suffix length needs to be at least");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please use stderr_only with the full message (and the length)? did you compare it with GNU's output?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compared against GNU 9.11: it rejects this with "numerical suffix start value is too large for the suffix length" plus the usage hint, because the start has more digits than the suffix length. we were printing "the suffix length needs to be at least 20" instead, so I added that same check for the start >= chunks case and the test now asserts the full message through usage_error.

Comment thread tests/by-util/test_split.rs Outdated
new_ucmd!()
.args(&["-n", "5", "--hex-suffixes=ffffffffffffffff", "/dev/null"])
.fails()
.stderr_contains("suffix length needs to be at least");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, please check the exact message. u64::MAX as f64 is 2^64, so i'm not sure we get the same length as GNU for hex

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, for hex it came out as 16 because of that f64 rounding. with the new check it errors before reaching the length calculation, so both cases now print the same message as GNU.

@SAY-5
SAY-5 force-pushed the split-fix-suffix-start-overflow branch from e22f5e1 to 91dc27e Compare October 25, 2026 05:49
@SAY-5
SAY-5 force-pushed the split-fix-suffix-start-overflow branch 2 times, most recently from adfbf5d to 4cb42bd Compare November 16, 2026 08:49
@SAY-5 SAY-5 changed the title split: avoid arithmetic overflow on a huge numeric or hex suffix start value split: avoid overflow on a suffix start with a huge number of chunks Nov 16, 2026
@SAY-5

SAY-5 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

rebased on main. #15649 already handles the oversized start value, so I dropped that part and this now only fixes the overflow that's left from the issue, a huge -n with a smaller start (-n r/1/18446744073709551615 --numeric-suffixes=5 still panics on main).

@sylvestre

Copy link
Copy Markdown
Contributor

it has been conflicting for more than 7 days, sorry! please rebase it

The add-overflow itself was fixed upstream in b51f325, which also tests
the error path with -a 2. Keep a regression test for the success path:
a numeric or hex suffix start below a chunk count of u64::MAX must still
auto-size the suffix and print the requested chunk.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@SAY-5
SAY-5 force-pushed the split-fix-suffix-start-overflow branch from 4cb42bd to 889a9fe Compare November 28, 2026 10:03
@SAY-5

SAY-5 commented Nov 28, 2026 via email

Copy link
Copy Markdown
Contributor Author

@sylvestre
sylvestre merged commit 114d850 into uutils:main Nov 29, 2026
93 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

split: arithmetic overflow (overflow-checks) on a huge --numeric-suffixes/--hex-suffixes start value

2 participants