Skip to content

csplit: avoid negate-with-overflow on an i32::MIN regex line offset - #13753

Open
leeewee wants to merge 1 commit into
uutils:mainfrom
leeewee:csplit-fix-offset-negate-overflow
Open

csplit: avoid negate-with-overflow on an i32::MIN regex line offset#13753
leeewee wants to merge 1 commit into
uutils:mainfrom
leeewee:csplit-fix-offset-negate-overflow

Conversation

@leeewee

@leeewee leeewee commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #13751

A csplit regex pattern may carry a signed line offset — /regex/OFFSET
or %regex%OFFSET — parsed into an i32. For a negative offset,
do_to_match computed -offset as usize. When OFFSET is i32::MIN
(-2147483648), the negation has no positive i32 counterpart and
overflows, panicking with attempt to negate with overflow under
overflow-checks (exit 134). GNU csplit rejects the offset gracefully.

Fix

Use offset.unsigned_abs(), which yields the magnitude of i32::MIN
without overflowing. The out-of-range offset then produces the normal
line number out of range error, matching GNU (and uutils' own default
release build).

Test

Adds test_up_to_match_negative_offset_min_i32 and
test_skip_to_match_negative_offset_min_i32, covering both the /regex/
and %regex% offset forms. They panic before the fix (the test build has
overflow-checks enabled) and pass after.

do_to_match computed `-offset as usize` for a negative `/regex/OFFSET`
(or `%regex%OFFSET`) offset. When OFFSET is i32::MIN the negation has no
i32 counterpart and overflows, panicking under overflow-checks. Use
`offset.unsigned_abs()`, which yields the magnitude without overflowing,
so the out-of-range offset produces the normal "line number out of range"
error on every build.
@codspeed-hq

codspeed-hq Bot commented Aug 5, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 18.29%

⚠️ 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.4 µs -18.29%

Tip

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


Comparing leeewee:csplit-fix-offset-negate-overflow (0c44621) 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.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/retry (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/cut/mb-non-utf8 is no longer failing!
Congrats! The gnu test tests/mv/mv-exchange is no longer failing!
Congrats! The gnu test tests/od/od-j is no longer failing!
Congrats! The gnu test tests/dd/no-allocate is now passing!
Note: The gnu test tests/misc/write-errors was skipped on 'main' but is now failing.

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.

csplit: arithmetic overflow (overflow-checks) on a regex pattern with offset -2147483648

1 participant