Skip to content

fix(pr): reject huge --column/-COLUMN counts instead of panicking (fixes #12996)#13002

Open
koopatroopa787 wants to merge 1 commit into
uutils:mainfrom
koopatroopa787:fix-pr-huge-column-panic
Open

fix(pr): reject huge --column/-COLUMN counts instead of panicking (fixes #12996)#13002
koopatroopa787 wants to merge 1 commit into
uutils:mainfrom
koopatroopa787:fix-pr-huge-column-panic

Conversation

@koopatroopa787

Copy link
Copy Markdown
Contributor

Summary

Fixes #12996.

pr --column N (or the -N shortcut) with an enormous but parseable N (e.g. 9999999999999999999) panics with capacity overflow and aborts (exit 134):

$ pr --column 9999999999999999999 /tmp/pr_in
thread 'main' panicked at src/uu/pr/src/pr.rs:1272:20:
capacity overflow

N parses fine as a usize (it's smaller than usize::MAX on 64-bit), but it's later used directly as the length of several Vec allocations in to_table(), to_table_across(), and to_table_short_file()vec![None; columns] — which overflows once columns * size_of::<Option<&FileLine>>() exceeds isize::MAX.

GNU pr rejects this up front:

$ /usr/bin/pr --column 9999999999999999999 /tmp/pr_in
/usr/bin/pr: invalid number of columns: ‘9999999999999999999’: Value too large for defined data type

Change

In src/uu/pr/src/pr.rs, after column_option_value is resolved (which already merges both the --column N and -N forms), reject any value above i32::MAX with 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_panic and test_huge_columns_shortcut_does_not_panic in tests/by-util/test_pr.rs covering both the long and short option forms. All 59 existing test_pr tests still pass.

 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>
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/rm/isatty (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/retry (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/symlink (passes in this run but fails in the 'main' branch)

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.

pr panics (capacity overflow) on a huge --column / -COLUMN count

1 participant