Skip to content

split: fix add-overflow in suffix-length calculation - #13754

Open
leeewee wants to merge 1 commit into
uutils:mainfrom
leeewee:split-fix-numeric-suffix-add-overflow
Open

split: fix add-overflow in suffix-length calculation#13754
leeewee wants to merge 1 commit into
uutils:mainfrom
leeewee:split-fix-numeric-suffix-add-overflow

Conversation

@leeewee

@leeewee leeewee commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #13749

split auto-computes the suffix length from the suffix start value
(--numeric-suffixes=N / --hex-suffixes=N) and the chunk count (-n).
Suffix::from did this as start as u64 + chunks, with no guard against
the sum exceeding u64::MAX. A start near u64::MAX, or a chunk count
near u64::MAX with a nonzero start, overflows the add and panics with
attempt to add with overflow under overflow-checks (exit 134).

Fix

Widen the sum to u128 so it can't overflow. The value only feeds a log
for the digit count, so results are identical for every in-range input,
and the out-of-range case now reports the normal
the suffix length needs to be at least N error instead of aborting —
matching GNU (which accepts such a start only once -a is large enough).

Tests

Adds three regression tests covering both operands and both radixes: a huge
decimal start, a huge hex start, and a huge -n chunk count. Each panics
before the fix (the test build enables overflow-checks) and passes after.

Suffix::from computed the auto suffix length from `start as u64 + chunks`,
which overflows when the numeric/hex suffix start (--numeric-suffixes /
--hex-suffixes) or the chunk count (-n) is near u64::MAX, panicking with
`attempt to add with overflow` under overflow-checks. Widen the sum to
u128 so it can't overflow; it only feeds a log for the digit count, so
results are unchanged for every in-range input and the out-of-range case
now reports the normal "suffix length needs to be at least N" error.
@codspeed-hq

codspeed-hq Bot commented Aug 5, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 18.31%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 346 untouched benchmarks
⏩ 46 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation df_with_path 571.4 µs 699.6 µs -18.31%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing leeewee:split-fix-numeric-suffix-add-overflow (383f289) with main (21d4e96)

Open in CodSpeed

Footnotes

  1. 46 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.

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

1 participant