René's URL Explorer Experiment


Title: Fix process abort on large float format precision by changjoon-park · Pull Request #7633 · RustPython/RustPython · GitHub

Open Graph Title: Fix process abort on large float format precision by changjoon-park · Pull Request #7633 · RustPython/RustPython

X Title: Fix process abort on large float format precision by changjoon-park · Pull Request #7633 · RustPython/RustPython

Description: Summary Formatting a float with a large precision aborts the interpreter instead of raising a Python exception. CPython returns a clean string on the same input. # Before $ ./rustpython -c "print(f'{1.5:.1000000}')" thread 'main' panicked at crates/literal/src/float.rs:135: Formatting argument out of range # → exit 101 (process abort) # After $ ./rustpython -c "print(f'{1.5:.1000000}')" 1.5 Root cause Rust's format!("{:.*}", n, x) macro panics when n exceeds the fmt runtime's internal precision limit. format_fixed in crates/literal/src/float.rs already caps n at u16::MAX before calling format!, but its sibling functions format_general and format_exponent — and the FormatType::Percentage branch in crates/common/src/format.rs — pass user-supplied precision straight through. A one-line user script (f"{x:.N}" with N ≳ 65535) triggers the abort. Affected format types: Type Before After f (fixed) OK (already capped) OK e / E (exponential) abort OK g / G (general) abort OK % (percent) abort OK default (no type) abort (routes to g) OK Fix Add FMT_MAX_PRECISION + clamp_fmt_precision() helper at module level in float.rs. Cap is u16::MAX - 1, not u16::MAX — {:.*e} hits a second assertion (ndigits > 0 in core::num::flt2dec) at exactly u16::MAX; the smaller value covers both {:.*} and {:.*e} uniformly. Apply the helper to: format_fixed (replacing existing ad-hoc cap — consistency only) format_exponent (new, at function entry) format_general (new, at each of three internal format! calls, with saturating arithmetic on derived precision values) FormatType::Percentage branch in common/src/format.rs (new) Complex-number formatting and old-style %-formatting dispatch to the same library functions, so they transitively benefit without separate changes. Why the cap is safe f64 carries only ~17 significant decimal digits. Precision beyond ~17 produces padding zeros (for f/e/%) or is silently trimmed (for g). Capping at ~65K is far beyond any user-meaningful precision and matches the existing format_fixed behavior already shipping in main. Verification $ cargo +1.94.0 build --release Finished `release` profile [optimized] target(s) in 40.54s $ ./target/release/rustpython -m test test_float test_fstring test_format All 3 tests OK. Total tests: run=162 $ ./target/release/rustpython extra_tests/snippets/builtin_format.py # (all assertions pass, including 7 new regression cases) Reliability audit (beyond the trigger path) Probed after the fix: 40 magnitude/type combinations: 10 values × 4 format types at precision 200_000 — 0.0, ±1.5, ±inf, nan, 1e-300, 1e300, f64::MAX, 5e-324. All return clean strings. Boundary precisions: 0 / 1 / 2 for each format type — outputs match expected ('{:.0g}'.format(1.5) == '2', etc.). Complex numbers: five format specs including .200000e — all OK (transitively via format_exponent). Old-style % formatting: '%.200000e' % 1.5 etc. — all OK (transitively via cformat.rs → format_fixed/format_exponent/format_general). Combined format specs: fill + align + width + precision, sign + precision, alternate form + precision, zero-pad + precision, grouping + precision — all OK. Defense-in-depth range: Rust's parser rejects precision > i32::MAX with ValueError("Precision too big"), so the guarded interval [0, i32::MAX] is now panic-free end-to-end. Related Prior fix using the same "cap before Rust format!" approach: format_fixed already did this; this PR extends the same pattern to its siblings. Adjacent hardening PRs using the same spirit (translate native failures into Python exceptions): #7630 (cyclic-AST SIGSEGV → RecursionError), #7632 (deep-JSON SIGSEGV → RecursionError). Summary by CodeRabbit Bug Fixes Float formatting now handles extreme precisions safely: percent formatting outputs "inf%" for infinite values, precision is clamped for fixed/exponential/general formats, and fractional digits are zero-padded when needed to match expected behavior. Tests Added regression tests covering very large precision values across f/e/g/% formats to ensure stable, non-crashing output and preserved NaN/Inf representations.

Open Graph Description: Summary Formatting a float with a large precision aborts the interpreter instead of raising a Python exception. CPython returns a clean string on the same input. # Before $ ./rustpython -c "pr...

X Description: Summary Formatting a float with a large precision aborts the interpreter instead of raising a Python exception. CPython returns a clean string on the same input. # Before $ ./rustpython -c &quo...

Opengraph URL: https://github.com/RustPython/RustPython/pull/7633

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:00998172-0070-ee9f-8099-d30d63517933
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idCACE:136CDA:117BD96:172D1E3:6B01E68C
html-safe-nonce1e9ee17911919a9bb374defa5086908124eb73e1eab07c5ef6e69a1a684e90ee
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQUNFOjEzNkNEQToxMTdCRDk2OjE3MkQxRTM6NkIwMUU2OEMiLCJ2aXNpdG9yX2lkIjoiODQ1MDQ0NjEzMzQ2OTI0MzAyMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac988ed7123f9b76eef0a7f9664c280ce800f0d16a3eaa324afc86cceb45a7e23c
hovercard-subject-tagpull_request:3552436376
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/RustPython/RustPython/pull/7633/files
twitter:imagehttps://avatars.githubusercontent.com/u/131537123?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/131537123?s=400&v=4
og:image:altSummary Formatting a float with a large precision aborts the interpreter instead of raising a Python exception. CPython returns a clean string on the same input. # Before $ ./rustpython -c "pr...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git
octolytics-dimension-user_id39710557
octolytics-dimension-user_loginRustPython
octolytics-dimension-repository_id135201145
octolytics-dimension-repository_nwoRustPython/RustPython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id135201145
octolytics-dimension-repository_network_root_nwoRustPython/RustPython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/RustPython/RustPython/pull/7633/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fpull%2F7633%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fpull%2F7633%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=RustPython%2FRustPython
Reloadhttps://github.com/RustPython/RustPython/pull/7633/files
Reloadhttps://github.com/RustPython/RustPython/pull/7633/files
Reloadhttps://github.com/RustPython/RustPython/pull/7633/files
RustPythonhttps://github.com/RustPython
RustPythonhttps://github.com/RustPython/RustPython
Codehttps://github.com/RustPython/RustPython
Issues195 (195)https://github.com/RustPython/RustPython/issues
Pull requests133 (133)https://github.com/RustPython/RustPython/pulls
Discussionshttps://github.com/RustPython/RustPython/discussions
Actionshttps://github.com/RustPython/RustPython/actions
Projectshttps://github.com/RustPython/RustPython/projects
Wikihttps://github.com/RustPython/RustPython/wiki
Security and qualityhttps://github.com/RustPython/RustPython/security
Insightshttps://github.com/RustPython/RustPython/insights
Sign up for GitHub https://github.com/signup?return_to=%2FRustPython%2FRustPython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FRustPython%2FRustPython%2Fissues%2Fnew%2Fchoose
youknowonehttps://github.com/youknowone
RustPython:mainhttps://github.com/RustPython/RustPython/tree/main
changjoon-park:fix-float-format-panichttps://github.com/changjoon-park/RustPython/tree/fix-float-format-panic
Conversation 4 https://github.com/RustPython/RustPython/pull/7633
Commits 5 https://github.com/RustPython/RustPython/pull/7633/commits
Checks 19 https://github.com/RustPython/RustPython/pull/7633/checks
Files changed https://github.com/RustPython/RustPython/pull/7633/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/7633/files
Fix process abort on large float format precision https://github.com/RustPython/RustPython/pull/7633/files#top
Show all changes 5 commits https://github.com/RustPython/RustPython/pull/7633/files
a3acff1 Fix process abort on large float format precision changjoon-park Apr 19, 2026 https://github.com/RustPython/RustPython/pull/7633/commits/a3acff119124cedbd2c2c25681b79967238b17a8
70e85d9 Address CodeRabbit review: split cap + drop redundant clamp changjoon-park Apr 19, 2026 https://github.com/RustPython/RustPython/pull/7633/commits/70e85d95740298649951d76e929477c0e474bcad
b142cf2 Fix ruff format: single-line precision clamp changjoon-park Apr 19, 2026 https://github.com/RustPython/RustPython/pull/7633/commits/b142cf228442c9743fbcaa2b07a3adae0a52cb7c
d4c8316 Address @youknowone review: byte-identical CPython parity at boundary changjoon-park Apr 20, 2026 https://github.com/RustPython/RustPython/pull/7633/commits/d4c8316abf6da6a58084db36cd7166e323db0d26
58c59d4 Clarify boundary test labels + add past-cap depth assertions changjoon-park Apr 20, 2026 https://github.com/RustPython/RustPython/pull/7633/commits/58c59d47027b20927928d827ddf6ea6736bfd7b9
Clear filters https://github.com/RustPython/RustPython/pull/7633/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/7633/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/7633/files
format.rs https://github.com/RustPython/RustPython/pull/7633/files#diff-47d8fa943b6ea1840ae9d06a3785a14c7a57610a113e4a7958709acb47e87e4c
float.rs https://github.com/RustPython/RustPython/pull/7633/files#diff-f11834b3af6a7f6f6ce1b28881798f4079c85d8300549c6f9de2b202da0625bd
builtin_format.py https://github.com/RustPython/RustPython/pull/7633/files#diff-06499a5d186ecb5e2a045765ae3b068f1511ba9cf90126b47f15acb58e18f2fc
crates/common/src/format.rshttps://github.com/RustPython/RustPython/pull/7633/files#diff-47d8fa943b6ea1840ae9d06a3785a14c7a57610a113e4a7958709acb47e87e4c
View file https://github.com/changjoon-park/RustPython/blob/58c59d47027b20927928d827ddf6ea6736bfd7b9/crates/common/src/format.rs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/7633/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/7633/files#diff-47d8fa943b6ea1840ae9d06a3785a14c7a57610a113e4a7958709acb47e87e4c
https://github.com/RustPython/RustPython/pull/7633/files#diff-47d8fa943b6ea1840ae9d06a3785a14c7a57610a113e4a7958709acb47e87e4c
crates/literal/src/float.rshttps://github.com/RustPython/RustPython/pull/7633/files#diff-f11834b3af6a7f6f6ce1b28881798f4079c85d8300549c6f9de2b202da0625bd
View file https://github.com/changjoon-park/RustPython/blob/58c59d47027b20927928d827ddf6ea6736bfd7b9/crates/literal/src/float.rs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/7633/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/7633/files#diff-f11834b3af6a7f6f6ce1b28881798f4079c85d8300549c6f9de2b202da0625bd
https://github.com/RustPython/RustPython/pull/7633/files#diff-f11834b3af6a7f6f6ce1b28881798f4079c85d8300549c6f9de2b202da0625bd
https://github.com/RustPython/RustPython/pull/7633/files#diff-f11834b3af6a7f6f6ce1b28881798f4079c85d8300549c6f9de2b202da0625bd
https://github.com/RustPython/RustPython/pull/7633/files#diff-f11834b3af6a7f6f6ce1b28881798f4079c85d8300549c6f9de2b202da0625bd
https://github.com/RustPython/RustPython/pull/7633/files#diff-f11834b3af6a7f6f6ce1b28881798f4079c85d8300549c6f9de2b202da0625bd
https://github.com/RustPython/RustPython/pull/7633/files#diff-f11834b3af6a7f6f6ce1b28881798f4079c85d8300549c6f9de2b202da0625bd
https://github.com/RustPython/RustPython/pull/7633/files#diff-f11834b3af6a7f6f6ce1b28881798f4079c85d8300549c6f9de2b202da0625bd
extra_tests/snippets/builtin_format.pyhttps://github.com/RustPython/RustPython/pull/7633/files#diff-06499a5d186ecb5e2a045765ae3b068f1511ba9cf90126b47f15acb58e18f2fc
View file https://github.com/changjoon-park/RustPython/blob/58c59d47027b20927928d827ddf6ea6736bfd7b9/extra_tests/snippets/builtin_format.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/7633/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/7633/files#diff-06499a5d186ecb5e2a045765ae3b068f1511ba9cf90126b47f15acb58e18f2fc
youknowonehttps://github.com/youknowone
Apr 20, 2026https://github.com/RustPython/RustPython/pull/7633/files#r3110769978
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/RustPython/RustPython/pull/7633/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/7633/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.