René's URL Explorer Experiment


Title: Bound AST nesting so deep source raises instead of crashing by sigmaith · Pull Request #8827 · RustPython/RustPython · GitHub

Open Graph Title: Bound AST nesting so deep source raises instead of crashing by sigmaith · Pull Request #8827 · RustPython/RustPython

X Title: Bound AST nesting so deep source raises instead of crashing by sigmaith · Pull Request #8827 · RustPython/RustPython

Description: Closes #7655 One of checkbox below must be checked. [ ] I did not use AI to write the code of this patch. This PR follows our AI policy Summary Deeply nested source killed the process with SIGSEGV instead of raising. From #7655: $ cargo run --release -- -c "import ast; ast.parse('x' + '+1'*5000)" [1] 72958 segmentation fault $ cargo run --release -- -c "compile('x' + '+1'*20000, '', 'exec')" [1] 72960 segmentation fault $ cargo run --release -- -c "compile('['*200000 + '1' + ']'*200000, '', 'exec')" [1] 72961 segmentation fault Why The parser grows its stack onto the heap when the native stack runs low, so it returns trees far deeper than the passes after it can walk. Every one of those passes recurses over the tree with no depth limit of its own. The symbol table does apply a limit, but it runs last, and compile(..., PyCF_ONLY_AST) — what ast.parse calls — returns before ever reaching it. What changed 1. Check AST depth right after parsing. The limit is CompileOpts::recursion_limit, the same value the symbol table already enforces, so no tree deeper than that reaches any of the walks that follow. 2. Count bracket nesting before parsing instead of after. The count only ever needed the source text, but it ran after parse(), so the parser had already built the whole tree. A tree nested that deep exhausts the stack when it is dropped, which no later check can prevent. CPython counts brackets in its tokenizer (Parser/lexer/lexer.c), so the tree is never built; it also frees the AST arena in one go, so it has no recursive teardown at all. Assisted-by: Claude Code:Opus 5 Summary by CodeRabbit Bug Fixes Excessively nested brackets now produce a syntax error during compilation and parsing; deeply nested expressions may produce a recursion error. Sources with ordinary nesting continue to compile, parse, and evaluate successfully. Nesting limits are checked before parsing and compilation proceed. String escape warnings are skipped when source fails the nesting check.

Open Graph Description: Closes #7655 One of checkbox below must be checked. [ ] I did not use AI to write the code of this patch. This PR follows our AI policy Summary Deeply nested source killed the process with SIG...

X Description: Closes #7655 One of checkbox below must be checked. [ ] I did not use AI to write the code of this patch. This PR follows our AI policy Summary Deeply nested source killed the process with SIG...

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

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:e2cd1b3d-7868-64a5-eeaf-b8c3c21cd26c
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE4AE:ADA9D:37A55A4:475C9F6:6B01E6D5
html-safe-nonce8c72923e21c80fadaaf72d025a9263da85b5de9955243ac7f21d4ebf8a2e116c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNEFFOkFEQTlEOjM3QTU1QTQ6NDc1QzlGNjo2QjAxRTZENSIsInZpc2l0b3JfaWQiOiIxODcyNzY1ODExOTg3NDQxMzY1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac8e2355ab7ef9e76629571b0357429105cf1b4d336ea1b667e15eef1729e18829
hovercard-subject-tagpull_request:4644280854
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/8827/files
twitter:imagehttps://avatars.githubusercontent.com/u/125195487?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/125195487?s=400&v=4
og:image:altCloses #7655 One of checkbox below must be checked. [ ] I did not use AI to write the code of this patch. This PR follows our AI policy Summary Deeply nested source killed the process with SIG...
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/8827/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fpull%2F8827%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%2F8827%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/8827/files
Reloadhttps://github.com/RustPython/RustPython/pull/8827/files
Reloadhttps://github.com/RustPython/RustPython/pull/8827/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
sigmaith:fix/deep-nesting-recursion-guardhttps://github.com/sigmaith/RustPython/tree/fix/deep-nesting-recursion-guard
Conversation 14 https://github.com/RustPython/RustPython/pull/8827
Commits 4 https://github.com/RustPython/RustPython/pull/8827/commits
Checks 28 https://github.com/RustPython/RustPython/pull/8827/checks
Files changed https://github.com/RustPython/RustPython/pull/8827/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8827/files
Bound AST nesting so deep source raises instead of crashing https://github.com/RustPython/RustPython/pull/8827/files#top
Show all changes 4 commits https://github.com/RustPython/RustPython/pull/8827/files
948f4d9 Bound AST nesting so deep source raises instead of crashing sigmaith Sep 21, 2026 https://github.com/RustPython/RustPython/pull/8827/commits/948f4d9067db511f928ddbe27ac12105bf0bc6d6
fa3fb02 Return Result from too_deeply_nested_error sigmaith Sep 26, 2026 https://github.com/RustPython/RustPython/pull/8827/commits/fa3fb026c71149a4a87219c47a7496bb23994010
4f39e6c Return Result from pre_parse_source_error too sigmaith Sep 26, 2026 https://github.com/RustPython/RustPython/pull/8827/commits/4f39e6c95a27bfb17544b27d38d601026cee2f89
79e8989 Drop exceeds_max_nesting for the check beside it sigmaith Sep 29, 2026 https://github.com/RustPython/RustPython/pull/8827/commits/79e8989014d84bdbc4255d9e2da6a96c5c913cac
Clear filters https://github.com/RustPython/RustPython/pull/8827/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8827/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8827/files
lib.rs https://github.com/RustPython/RustPython/pull/8827/files#diff-560e1ff98a1fe1161356b6c726aeb89f8c5e9764ccd2f4fb4dfa7143508d09e7
_ast.rs https://github.com/RustPython/RustPython/pull/8827/files#diff-abdef7b5c5b2a09ab3af5a77d683e79ae937bd93b5411799efd4101aacbc7411
compile.rs https://github.com/RustPython/RustPython/pull/8827/files#diff-e7f70f57a7775d5472ffe0e4fe2f28f1c386fad78bef2ba2c46fd7f2224fa89e
syntax_deep_nesting.py https://github.com/RustPython/RustPython/pull/8827/files#diff-21bb1cd57c35ab92a7b92a43f07e290405dde809fbb6221f94870b69915929c9
crates/compiler/src/lib.rshttps://github.com/RustPython/RustPython/pull/8827/files#diff-560e1ff98a1fe1161356b6c726aeb89f8c5e9764ccd2f4fb4dfa7143508d09e7
View file https://github.com/sigmaith/RustPython/blob/79e8989014d84bdbc4255d9e2da6a96c5c913cac/crates/compiler/src/lib.rs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/8827/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/8827/files#diff-560e1ff98a1fe1161356b6c726aeb89f8c5e9764ccd2f4fb4dfa7143508d09e7
https://github.com/RustPython/RustPython/pull/8827/files#diff-560e1ff98a1fe1161356b6c726aeb89f8c5e9764ccd2f4fb4dfa7143508d09e7
https://github.com/RustPython/RustPython/pull/8827/files#diff-560e1ff98a1fe1161356b6c726aeb89f8c5e9764ccd2f4fb4dfa7143508d09e7
https://github.com/RustPython/RustPython/pull/8827/files#diff-560e1ff98a1fe1161356b6c726aeb89f8c5e9764ccd2f4fb4dfa7143508d09e7
https://github.com/RustPython/RustPython/pull/8827/files#diff-560e1ff98a1fe1161356b6c726aeb89f8c5e9764ccd2f4fb4dfa7143508d09e7
https://github.com/RustPython/RustPython/pull/8827/files#diff-560e1ff98a1fe1161356b6c726aeb89f8c5e9764ccd2f4fb4dfa7143508d09e7
https://github.com/RustPython/RustPython/pull/8827/files#diff-560e1ff98a1fe1161356b6c726aeb89f8c5e9764ccd2f4fb4dfa7143508d09e7
https://github.com/RustPython/RustPython/pull/8827/files#diff-560e1ff98a1fe1161356b6c726aeb89f8c5e9764ccd2f4fb4dfa7143508d09e7
https://github.com/RustPython/RustPython/pull/8827/files#diff-560e1ff98a1fe1161356b6c726aeb89f8c5e9764ccd2f4fb4dfa7143508d09e7
https://github.com/RustPython/RustPython/pull/8827/files#diff-560e1ff98a1fe1161356b6c726aeb89f8c5e9764ccd2f4fb4dfa7143508d09e7
https://github.com/RustPython/RustPython/pull/8827/files#diff-560e1ff98a1fe1161356b6c726aeb89f8c5e9764ccd2f4fb4dfa7143508d09e7
https://github.com/RustPython/RustPython/pull/8827/files#diff-560e1ff98a1fe1161356b6c726aeb89f8c5e9764ccd2f4fb4dfa7143508d09e7
https://github.com/RustPython/RustPython/pull/8827/files#diff-560e1ff98a1fe1161356b6c726aeb89f8c5e9764ccd2f4fb4dfa7143508d09e7
crates/vm/src/stdlib/_ast.rshttps://github.com/RustPython/RustPython/pull/8827/files#diff-abdef7b5c5b2a09ab3af5a77d683e79ae937bd93b5411799efd4101aacbc7411
View file https://github.com/sigmaith/RustPython/blob/79e8989014d84bdbc4255d9e2da6a96c5c913cac/crates/vm/src/stdlib/_ast.rs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/8827/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/8827/files#diff-abdef7b5c5b2a09ab3af5a77d683e79ae937bd93b5411799efd4101aacbc7411
https://github.com/RustPython/RustPython/pull/8827/files#diff-abdef7b5c5b2a09ab3af5a77d683e79ae937bd93b5411799efd4101aacbc7411
https://github.com/RustPython/RustPython/pull/8827/files#diff-abdef7b5c5b2a09ab3af5a77d683e79ae937bd93b5411799efd4101aacbc7411
https://github.com/RustPython/RustPython/pull/8827/files#diff-abdef7b5c5b2a09ab3af5a77d683e79ae937bd93b5411799efd4101aacbc7411
crates/vm/src/vm/compile.rshttps://github.com/RustPython/RustPython/pull/8827/files#diff-e7f70f57a7775d5472ffe0e4fe2f28f1c386fad78bef2ba2c46fd7f2224fa89e
View file https://github.com/sigmaith/RustPython/blob/79e8989014d84bdbc4255d9e2da6a96c5c913cac/crates/vm/src/vm/compile.rs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/8827/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/8827/files#diff-e7f70f57a7775d5472ffe0e4fe2f28f1c386fad78bef2ba2c46fd7f2224fa89e
https://github.com/RustPython/RustPython/pull/8827/files#diff-e7f70f57a7775d5472ffe0e4fe2f28f1c386fad78bef2ba2c46fd7f2224fa89e
https://github.com/RustPython/RustPython/pull/8827/files#diff-e7f70f57a7775d5472ffe0e4fe2f28f1c386fad78bef2ba2c46fd7f2224fa89e
https://github.com/RustPython/RustPython/pull/8827/files#diff-e7f70f57a7775d5472ffe0e4fe2f28f1c386fad78bef2ba2c46fd7f2224fa89e
coderabbitaihttps://github.com/apps/coderabbitai
Sep 29, 2026https://github.com/RustPython/RustPython/pull/8827/files#r4134987858
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8827/files
https://github.com/RustPython/RustPython/pull/8827/files#diff-e7f70f57a7775d5472ffe0e4fe2f28f1c386fad78bef2ba2c46fd7f2224fa89e
https://github.com/RustPython/RustPython/pull/8827/files#diff-e7f70f57a7775d5472ffe0e4fe2f28f1c386fad78bef2ba2c46fd7f2224fa89e
extra_tests/snippets/syntax_deep_nesting.pyhttps://github.com/RustPython/RustPython/pull/8827/files#diff-21bb1cd57c35ab92a7b92a43f07e290405dde809fbb6221f94870b69915929c9
View file https://github.com/sigmaith/RustPython/blob/79e8989014d84bdbc4255d9e2da6a96c5c913cac/extra_tests/snippets/syntax_deep_nesting.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/8827/{{ revealButtonHref }}
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8827/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.