Skip to content

fix(builtins): clamp printf precision to prevent panic on large values#1010

Merged
chaliy merged 1 commit intomainfrom
fix/issue-1003-printf-precision-panic
Apr 2, 2026
Merged

fix(builtins): clamp printf precision to prevent panic on large values#1010
chaliy merged 1 commit intomainfrom
fix/issue-1003-printf-precision-panic

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Apr 2, 2026

Summary

  • Clamp user-controlled precision to 10000 in FormatSpec::parse
  • Prevents thread panic when precision exceeds Rust's format! u16 limit (65535)

What & Why

printf "%.65536f" 1.0 caused a thread panic in Rust's format! macro, dumping a full stack backtrace to stderr that leaks internal paths and dependency versions. Now precision is clamped to a safe maximum (10000).

Tests Added

  • test_large_precision_no_panic — verifies no panic on precision > 65535
  • test_normal_precision_still_works — verifies normal precision works correctly

Closes #1003

Closes #1003 — format! panics when precision exceeds u16::MAX (65535).
Clamp user-controlled precision to 10000 in FormatSpec::parse to prevent
thread panics and associated backtrace information disclosure.
@chaliy chaliy merged commit dfde6a1 into main Apr 2, 2026
27 checks passed
@chaliy chaliy deleted the fix/issue-1003-printf-precision-panic branch April 2, 2026 10:37
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 precision > 65535, leaking stack backtrace

1 participant