unexpand: reject too-large --tabs increment instead of overflowing#13383
Merged
Conversation
…wing
`--tabs=N,+M` adds an extra tab stop at `N + M`. When `N` is near
`usize::MAX` the sum overflowed: it aborts under overflow checks and, in
release builds, wraps to a bogus stop that then fails the ascending check
for the wrong reason. Use `checked_add` and reject the value as
`TabSizeTooLarge` ("tab stop value is too large"), matching GNU and the
existing handling of a single over-large tab number in `parse_tab_num`.
Fixes uutils#13378
|
GNU testsuite comparison: |
sylvestre
reviewed
Jul 13, 2026
Comment on lines
+120
to
+122
| // A near-maximal last stop plus the increment can exceed `usize::MAX`. | ||
| // Reject it as too large (matching GNU) instead of overflowing, which | ||
| // aborts under overflow checks and wraps to a bogus stop otherwise. |
Contributor
There was a problem hiding this comment.
a one line comment is probably enough
Address review feedback: a one-line comment is enough.
sylvestre
reviewed
Jul 13, 2026
Comment on lines
+257
to
+259
| // `--tabs=N,+M` adds one stop at `N + M`. When `N` is near `usize::MAX`, | ||
| // that sum must be rejected as too large rather than overflowing (which | ||
| // aborts under overflow checks and wraps to a bogus stop otherwise). |
Address review feedback: a one-line comment is enough.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
unexpand --tabs=N,+Madds one tab stop atN + M. WhenNis nearusize::MAX, that addition overflowed:under overflow checks (debug builds) it aborts:
in release builds it wraps to
0, which then fails the "tab sizes must be ascending" check for the wrong reason.Use
checked_addand reject the value asTabSizeTooLarge("tab stop value is too large"), matching GNU and the existing handling of a single over-large tab number inparse_tab_num.Fixes #13378.
Test
Added
test_extended_tabstop_increment_overflowasserting--tabs=<usize::MAX>,+1fails with "tab stop value is too large". All 37unexpandtests pass;cargo clippy --features unexpand --all-targets -- -D warningsandcargo fmtare clean.