printf: avoid formatter panic on large widths#12620
Open
wondr-wclabs wants to merge 1 commit into
Open
Conversation
|
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.
What changed
This replaces the remaining dynamic-width padding calls in the shared printf formatting code with bounded manual padding writes.
The affected paths were:
spec.rs, which panicked for%111111cnum_format.rs, which panicked for%111111.1dand%111111.1fWhy
The existing guard rejects clearly pathological output widths above
1_000_000, but these reports use widths around111_111: large, but still below that guard. The panic came from feeding those widths into Rust's dynamic formatting machinery, which has a smaller internal bound and panics withFormatting argument out of range.Lowering the project guard to that internal formatter limit would avoid the panic, but it would also reject valid finite
printfwidths that GNU accepts. Writing padding in chunks keeps the intended behavior: valid large widths can be emitted, while absurd padding requests still return the existing write error throughcheck_width.Validation
cargo fmt --checkgit diff --checkcargo test --no-default-features --features printf --test tests test_printf::test_large_but_allowed_width_format -- --nocapturecargo test --no-default-features --features printf --test tests test_printf::test_large_width_format -- --nocapturecargo test --no-default-features --features printf --test tests test_printf::test_extreme_field_width_overflow -- --nocapturecargo test --no-default-features --features printf --test tests test_printf -- --nocapturecargo test -p uucore --features format format -- --nocapturecargo clippy -p uucore --features format -- -D warningscargo clippy --no-default-features --features printf --test tests -- -D warningsFixes #12592.
Fixes #12593.