René's URL Explorer Experiment


Title: Fix stack overflow on deeply-nested JSON in json.loads() by changjoon-park · Pull Request #7632 · RustPython/RustPython · GitHub

Open Graph Title: Fix stack overflow on deeply-nested JSON in json.loads() by changjoon-park · Pull Request #7632 · RustPython/RustPython

X Title: Fix stack overflow on deeply-nested JSON in json.loads() by changjoon-park · Pull Request #7632 · RustPython/RustPython

Description: Summary json.loads() on a deeply-nested array or object overflows the native Rust stack and crashes the interpreter process with SIGSEGV. CPython raises RecursionError on the same input. import json json.loads('[' * 50000 + ']' * 50000) # RustPython (before): SIGSEGV (exit 139) # CPython: RecursionError: maximum recursion depth exceeded # RustPython (after): RecursionError: maximum recursion depth exceeded while # decoding a JSON object from a string Root cause The scanner has a mutual-recursion chain in crates/stdlib/src/json.rs: JsonScanner::parse_object / parse_array -> JsonScanner::call_scan_once -> JsonScanner::parse_object / parse_array (recurse) call_scan_once is the single choke point every descent passes through, but it wasn't wrapped in a recursion guard. Each nesting level consumes a pair of Rust stack frames (parse_X + call_scan_once), so input depth ~45k exhausts the 8 MB main thread stack on macOS and the OS kills the process with SIGSEGV. CPython's Modules/_json.c handles this with _Py_EnterRecursiveCall(\" while decoding a JSON object from a string\"), which translates native recursion into RecursionError at sys.getrecursionlimit(). Fix Wrap the body of call_scan_once with vm.with_recursion(\"while decoding a JSON object from a string\", || { ... }). Same machinery RustPython already uses for comparison, __repr__, __subclasscheck__, and AST traversal (see protocol/object.rs and stdlib/_ast/node.rs). The guard is placed at call_scan_once rather than on parse_object / parse_array individually because every recursive descent funnels through call_scan_once — one wrap covers array, object, and alternating nesting with a single point of maintenance. Verification $ cargo +1.94.0 build --release Finished \`release\` profile [optimized] target(s) in 41s $ ./target/release/rustpython -c \"import json; json.loads('[' * 50000 + ']' * 50000)\" Traceback (most recent call last): File \"\", line 1, in RecursionError: maximum recursion depth exceeded while decoding a JSON object from a string $ ./target/release/rustpython extra_tests/snippets/stdlib_json.py (passes silently — includes 3 new regression cases) $ ./target/release/rustpython -m test test_json Ran 214 tests in 6.700s OK (skipped=9, expected failures=13) Result: SUCCESS Tested surfaces Input Before After '[' * 50000 + ']' * 50000 SIGSEGV RecursionError '[' * 500000 + ']' * 500000 SIGSEGV RecursionError '{\"a\":' * 100000 + '1' + '}' * 100000 SIGSEGV RecursionError ('[{\"x\":' * 100000) + '1' + ('}]' * 100000) SIGSEGV RecursionError '[1, 2, [3, [4, [5]]]]' OK OK (no regression) '{\"a\": {\"b\": {\"c\": 1}}}' OK OK (no regression) CPython parity note After the fix, RustPython raises RecursionError at JSON depth >= ~1000 (VM default recursion_limit). CPython raises it at depth >= ~10000 due to a different stack-headroom heuristic in _Py_EnterRecursiveCall. Both refuse to crash; exact threshold is tunable via sys.setrecursionlimit(). Real-world JSON is rarely deeper than 50 levels, so the difference is not user-visible in practice. Scope In: recursion guard on call_scan_once — covers all three nesting patterns above Out: encoder side (iterative, already safe), string/number parsing (non-recursive), scan_once Python-callback fallback path (already counted by VM frame machinery) Related Prior security fix using the same vm.with_recursion pattern: #7630 (cyclic AST in compile()) CPython reference: Modules/_json.c scanner_call / _scan_once uses _Py_EnterRecursiveCall Summary by CodeRabbit Bug Fixes JSON parser now raises RecursionError when decoding extremely deeply nested JSON structures (arrays, objects exceeding ~100,000 nesting levels) instead of causing potential stack overflow crashes. Tests Added regression tests for JSON parsing with extremely deeply nested arrays, objects, and alternating nesting patterns.

Open Graph Description: Summary json.loads() on a deeply-nested array or object overflows the native Rust stack and crashes the interpreter process with SIGSEGV. CPython raises RecursionError on the same input. import jso...

X Description: Summary json.loads() on a deeply-nested array or object overflows the native Rust stack and crashes the interpreter process with SIGSEGV. CPython raises RecursionError on the same input. import jso...

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

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:6147ed51-a83b-684c-a0ce-4e0d49f62180
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE68E:26ECEB:393E2B3:48C7629:6B01E3F9
html-safe-nonce6f44c05b0017bbb68992d387c33e2e69ed3a1cd2754adb1d3663461c40b976ca
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNjhFOjI2RUNFQjozOTNFMkIzOjQ4Qzc2Mjk6NkIwMUUzRjkiLCJ2aXNpdG9yX2lkIjoiODY4NzgwMDI5NDEyNzU1OTY3MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmace7653c335d5d729376129b436bb1343bce487dd888fb8966840c94a0e9c7147e
hovercard-subject-tagpull_request:3552364176
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/7632/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 json.loads() on a deeply-nested array or object overflows the native Rust stack and crashes the interpreter process with SIGSEGV. CPython raises RecursionError on the same input. import jso...
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/7632/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fpull%2F7632%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%2F7632%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/7632/files
Reloadhttps://github.com/RustPython/RustPython/pull/7632/files
Reloadhttps://github.com/RustPython/RustPython/pull/7632/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-json-stack-overflowhttps://github.com/changjoon-park/RustPython/tree/fix-json-stack-overflow
Conversation 5 https://github.com/RustPython/RustPython/pull/7632
Commits 2 https://github.com/RustPython/RustPython/pull/7632/commits
Checks 20 https://github.com/RustPython/RustPython/pull/7632/checks
Files changed https://github.com/RustPython/RustPython/pull/7632/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/7632/files
Fix stack overflow on deeply-nested JSON in json.loads() https://github.com/RustPython/RustPython/pull/7632/files#top
Show all changes 2 commits https://github.com/RustPython/RustPython/pull/7632/files
ccc05d6 Fix stack overflow on deeply-nested JSON in json.loads() changjoon-park Apr 19, 2026 https://github.com/RustPython/RustPython/pull/7632/commits/ccc05d606f4bc12e861cd22473fac6c59dad4242
566a197 Enable test_highly_nested_objects_decoding changjoon-park Apr 20, 2026 https://github.com/RustPython/RustPython/pull/7632/commits/566a197c3124fbc6027511a6da42da3c23acf5da
Clear filters https://github.com/RustPython/RustPython/pull/7632/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/7632/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/7632/files
test_recursion.py https://github.com/RustPython/RustPython/pull/7632/files#diff-0d3622ac71df7d9ebd95166ed0ade40c2aa65b9ece1b180a20802912736284e6
json.rs https://github.com/RustPython/RustPython/pull/7632/files#diff-178128486470adaa06dc096deddc4f7da63b1af9c0555e93fed81ae66c6e5f5e
stdlib_json.py https://github.com/RustPython/RustPython/pull/7632/files#diff-b1966af22d77553be8111256ab2fed6717a1129f05221bf5cb038a568313b6b7
Lib/test/test_json/test_recursion.pyhttps://github.com/RustPython/RustPython/pull/7632/files#diff-0d3622ac71df7d9ebd95166ed0ade40c2aa65b9ece1b180a20802912736284e6
View file https://github.com/changjoon-park/RustPython/blob/566a197c3124fbc6027511a6da42da3c23acf5da/Lib/test/test_json/test_recursion.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/7632/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/7632/files#diff-0d3622ac71df7d9ebd95166ed0ade40c2aa65b9ece1b180a20802912736284e6
https://github.com/RustPython/RustPython/pull/7632/files#diff-0d3622ac71df7d9ebd95166ed0ade40c2aa65b9ece1b180a20802912736284e6
crates/stdlib/src/json.rshttps://github.com/RustPython/RustPython/pull/7632/files#diff-178128486470adaa06dc096deddc4f7da63b1af9c0555e93fed81ae66c6e5f5e
View file https://github.com/changjoon-park/RustPython/blob/566a197c3124fbc6027511a6da42da3c23acf5da/crates/stdlib/src/json.rs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/7632/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/7632/files#diff-178128486470adaa06dc096deddc4f7da63b1af9c0555e93fed81ae66c6e5f5e
https://github.com/RustPython/RustPython/pull/7632/files#diff-178128486470adaa06dc096deddc4f7da63b1af9c0555e93fed81ae66c6e5f5e
extra_tests/snippets/stdlib_json.pyhttps://github.com/RustPython/RustPython/pull/7632/files#diff-b1966af22d77553be8111256ab2fed6717a1129f05221bf5cb038a568313b6b7
View file https://github.com/changjoon-park/RustPython/blob/566a197c3124fbc6027511a6da42da3c23acf5da/extra_tests/snippets/stdlib_json.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/7632/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/7632/files#diff-b1966af22d77553be8111256ab2fed6717a1129f05221bf5cb038a568313b6b7
Please reload this pagehttps://github.com/RustPython/RustPython/pull/7632/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.