Skip to content

printf: avoid panic on large numeric field widths - #13857

Open
Air-crypto wants to merge 2 commits into
uutils:mainfrom
Air-crypto:air-crypto/prinft-large-field-width-fix
Open

printf: avoid panic on large numeric field widths#13857
Air-crypto wants to merge 2 commits into
uutils:mainfrom
Air-crypto:air-crypto/prinft-large-field-width-fix

Conversation

@Air-crypto

Copy link
Copy Markdown

Fixes #13850.

Write numeric field padding in bounded chunks instead of passing widths above u16::MAX to Rust's formatting machinery. This prevents %65536d from panicking and adds a regression test for the expected 65,536-byte output.

Tests passed:

  • cargo test --no-default-features --features printf test_printf::
  • cargo test -p uucore
  • cargo clippy --no-default-features --features printf --all-targets -- -D warnings
  • cargo fmt --all -- --check

@github-actions

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 148.93 MB (+316 KB, +0.21%)

Significant per-binary changes:
  install     1.24 MB ->    1.32 MB  (+80 KB, +6.29%)
  mkdir       1.09 MB ->    1.17 MB  (+80 KB, +7.14%)
  mkfifo      1.09 MB ->    1.16 MB  (+76 KB, +6.83%)
  mknod       1.09 MB ->    1.17 MB  (+76 KB, +6.79%)

}

fn write_padding(writer: &mut impl Write, byte: u8, mut len: usize) -> std::io::Result<()> {
const BUFFER_SIZE: usize = 1024;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please document why 1024

@sylvestre sylvestre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm if the ci is happy

@codspeed-hq

codspeed-hq Bot commented Aug 11, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 18.61%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 346 untouched benchmarks
⏩ 46 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation df_with_path 573.7 µs 704.9 µs -18.61%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing Air-crypto:air-crypto/prinft-large-field-width-fix (bc89833) with main (822aa83)

Open in CodSpeed

Footnotes

  1. 46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions

Copy link
Copy Markdown

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/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/date/resolution (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)
Congrats! The gnu test tests/tail/pipe-f2 is no longer failing!
Note: The gnu test tests/seq/seq-epipe is now being skipped but was previously 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.

printf: panics on a numeric field width above 65535 (%65536d)

2 participants