Skip to content

printf: avoid formatter panic on large widths#12620

Open
wondr-wclabs wants to merge 1 commit into
uutils:mainfrom
wondr-wclabs:codex/printf-large-char-width
Open

printf: avoid formatter panic on large widths#12620
wondr-wclabs wants to merge 1 commit into
uutils:mainfrom
wondr-wclabs:codex/printf-large-char-width

Conversation

@wondr-wclabs
Copy link
Copy Markdown

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:

  • string/character padding in spec.rs, which panicked for %111111c
  • numeric output padding in num_format.rs, which panicked for %111111.1d and %111111.1f

Why

The existing guard rejects clearly pathological output widths above 1_000_000, but these reports use widths around 111_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 with Formatting argument out of range.

Lowering the project guard to that internal formatter limit would avoid the panic, but it would also reject valid finite printf widths 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 through check_width.

Validation

  • cargo fmt --check
  • git diff --check
  • cargo test --no-default-features --features printf --test tests test_printf::test_large_but_allowed_width_format -- --nocapture
  • cargo test --no-default-features --features printf --test tests test_printf::test_large_width_format -- --nocapture
  • cargo test --no-default-features --features printf --test tests test_printf::test_extreme_field_width_overflow -- --nocapture
  • cargo test --no-default-features --features printf --test tests test_printf -- --nocapture
  • cargo test -p uucore --features format format -- --nocapture
  • cargo clippy -p uucore --features format -- -D warnings
  • cargo clippy --no-default-features --features printf --test tests -- -D warnings

Fixes #12592.
Fixes #12593.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 5, 2026

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/inotify-dir-recreate (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)
Congrats! The gnu test tests/dd/no-allocate is now passing!
Congrats! The gnu test tests/seq/seq-epipe is now passing!

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.

bug: printf panic again with '%111111c' bug: printf panic again with '%d' & '%f' second time

1 participant