Skip to content

stat: avoid printf formatter panics#12621

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

stat: avoid printf formatter panics#12621
wondr-wclabs wants to merge 1 commit into
uutils:mainfrom
wondr-wclabs:codex/stat-large-printf-width

Conversation

@wondr-wclabs
Copy link
Copy Markdown

What changed

This updates stat --printf formatting so large but finite widths/precisions no longer go through Rust's dynamic-width formatting machinery.

The change covers the reported panic paths in #12594:

  • field width padding such as %111111.1d and %111111.1f
  • numeric precision zero-padding such as %.100000d, %.100000f, %.111111s, and %.111111a

Why

The panic was not caused by stat metadata itself. It came from formatting calls like {result:>width$} and {num:0>p$x}. Rust's formatter has an internal bound for dynamic width/precision and panics with Formatting argument out of range for values that are still finite and reasonable for command output tests.

Rather than lowering accepted stat --printf widths, this writes padding in chunks and builds numeric zero-padding explicitly. That keeps large finite output possible while avoiding formatter panics. For string widths, the helper counts chars() before padding so it preserves the old Rust formatter width behavior for multibyte UTF-8 strings, instead of accidentally switching to byte-width alignment.

Validation

  • cargo test --no-default-features --features stat --test tests test_stat::test_printf_large_width_and_precision_do_not_panic -- --nocapture
  • cargo test --no-default-features --features stat --test tests test_stat -- --nocapture
  • cargo test -p uu_stat -- --nocapture
  • cargo clippy -p uu_stat -- -D warnings
  • cargo clippy --no-default-features --features stat --test tests -- -D warnings
  • cargo fmt --check
  • git diff --check

Fixes #12594.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 5, 2026

GNU testsuite comparison:

Note: The gnu test tests/cut/bounded-memory is now being skipped but was previously passing.

@wondr-wclabs wondr-wclabs force-pushed the codex/stat-large-printf-width branch from 1c7ab3e to c5ebda6 Compare June 6, 2026 00:48
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: stat panics with --printf

1 participant