nl: reject -w values > i32::MAX to avoid capacity-overflow panic#13348
Open
koopatroopa787 wants to merge 1 commit into
Open
nl: reject -w values > i32::MAX to avoid capacity-overflow panic#13348koopatroopa787 wants to merge 1 commit into
koopatroopa787 wants to merge 1 commit into
Conversation
GNU nl bounds --number-width/-w to [1, 2147483647] and exits with "Numerical result out of range" for larger values. Without this guard, `printf '\n' | nl -w 9223372036854775807` panics with "capacity overflow" because `" ".repeat(number_width + 1)` overflows isize. Fixes uutils#13347
Contributor
|
Please validate it by clap native way instead. |
|
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
printf '\n' | nl -w 9223372036854775807aborts with:because
" ".repeat(settings.number_width + 1)innl.rstriggers a capacity overflow whennumber_widthis nearusize::MAX.GNU
nlbounds--number-width/-wto[1, 2147483647](i32::MAX) and exits with:Fix
In
src/uu/nl/src/helper.rs, tighten the existingNUMBER_WIDTHmatch arm to also reject values >i32::MAX, reusing the existingnl-error-invalid-line-widthtranslation (which already says "Numerical result out of range"):Tests
Two new tests in
tests/by-util/test_nl.rs:test_number_width_too_large— verifies-w 2147483648fails with the expected errortest_number_width_max_i32— verifies-w 2147483647succeeds (boundary)Fixes #13347