fix(pr): reject huge --column/-COLUMN counts instead of panicking (fixes #12996)#13002
Open
koopatroopa787 wants to merge 1 commit into
Open
fix(pr): reject huge --column/-COLUMN counts instead of panicking (fixes #12996)#13002koopatroopa787 wants to merge 1 commit into
koopatroopa787 wants to merge 1 commit into
Conversation
uutils#12996) A column count that parses as a valid usize but is enormous (e.g. 9999999999999999999) overflows the Vec allocations in to_table(), to_table_across(), and to_table_short_file(), causing a "capacity overflow" panic and abort (exit 134). Reject column counts above i32::MAX up front with a GNU-style "Value too large for defined data type" error and exit 1, matching GNU pr's behavior. Add regression tests for both the --column and -COLUMN forms. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
GNU testsuite comparison: |
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
Fixes #12996.
pr --column N(or the-Nshortcut) with an enormous but parseableN(e.g.9999999999999999999) panics withcapacity overflowand aborts (exit 134):Nparses fine as ausize(it's smaller thanusize::MAXon 64-bit), but it's later used directly as the length of severalVecallocations into_table(),to_table_across(), andto_table_short_file()—vec![None; columns]— which overflows oncecolumns * size_of::<Option<&FileLine>>()exceedsisize::MAX.GNU
prrejects this up front:Change
In
src/uu/pr/src/pr.rs, aftercolumn_option_valueis resolved (which already merges both the--column Nand-Nforms), reject any value abovei32::MAXwith the same "Value too large for defined data type" message GNU uses, returning exit code 1 instead of panicking.Tests
Added
test_huge_columns_does_not_panicandtest_huge_columns_shortcut_does_not_panicintests/by-util/test_pr.rscovering both the long and short option forms. All 59 existingtest_prtests still pass.