Skip to content

printf, seq: fix abort on large field width and precision#13460

Open
eyupcanakman wants to merge 1 commit into
uutils:mainfrom
eyupcanakman:fix/printf-large-width-precision-panic
Open

printf, seq: fix abort on large field width and precision#13460
eyupcanakman wants to merge 1 commit into
uutils:mainfrom
eyupcanakman:fix/printf-large-width-precision-panic

Conversation

@eyupcanakman

Copy link
Copy Markdown
Contributor

printf and seq abort with SIGABRT on a large field width or precision:

printf '%.70000f' 1
printf '%70000d' 1
printf '%500000s' x
seq -f '%.70000f' 1 1

Rust's formatting machinery panics once a dynamic width or precision passes u16::MAX, and the release build turns that panic into an abort. GNU produces the padded output, so these now do too.

While tracing it I found a second bug in the same path. printf '%.1000f' 1 printed 1 instead of 1. and 1000 zeros, because bigdecimal's Display stops padding past 1000 digits. The %f formatter now assembles the digits directly, which fixes both. Padding is written in fixed chunks so a wide field costs no extra memory.

#12620 uses the same chunked-padding approach for the width case. This also handles the large precision and the truncation, which #12620 and #12603 leave unfixed.

seq's own precision detection derives an unbounded value from the exponent text (seq 1e-3000000000 1e-3000000000), which this does not touch. That path is tracked in #13221.

Fixes #12708

A field width or precision above u16::MAX made Rust's formatting machinery panic, which the release build turns into a SIGABRT, so `printf '%70000d' 1` and `seq -f '%.70000f' 1 1` aborted where GNU pads the output.

The %f formatter now assembles the decimal digits directly instead of going through bigdecimal's Display, which also fixes `printf '%.1000f' 1` printing `1` rather than `1.` and 1000 zeros (Display stops padding past 1000 digits). Padding is written in fixed chunks so a wide field costs no extra memory.

Fixes uutils#12708
@codspeed-hq

codspeed-hq Bot commented Jul 19, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 18.37%

⚠️ 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 improved benchmark
✅ 338 untouched benchmarks
⏩ 46 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation seq_formatted 94.7 ms 80 ms +18.37%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing eyupcanakman:fix/printf-large-width-precision-panic (76445dd) with main (8894319)

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.

@sylvestre

Copy link
Copy Markdown
Contributor

Please fix the job issue

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/seq still panic on large float precision and field width after #12572 integer-precision fix

2 participants