stat: avoid printf formatter panics#12621
Open
wondr-wclabs wants to merge 1 commit into
Open
Conversation
|
GNU testsuite comparison: |
1c7ab3e to
c5ebda6
Compare
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 updates
stat --printfformatting 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:
%111111.1dand%111111.1f%.100000d,%.100000f,%.111111s, and%.111111aWhy
The panic was not caused by
statmetadata 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 withFormatting argument out of rangefor values that are still finite and reasonable for command output tests.Rather than lowering accepted
stat --printfwidths, 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 countschars()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 -- --nocapturecargo test --no-default-features --features stat --test tests test_stat -- --nocapturecargo test -p uu_stat -- --nocapturecargo clippy -p uu_stat -- -D warningscargo clippy --no-default-features --features stat --test tests -- -D warningscargo fmt --checkgit diff --checkFixes #12594.