René's URL Explorer Experiment


Title: Compiler crash: inlined comprehensions overflow `_PyCfgExceptStack`, bypassing the `u_nfblocks` block-nesting limit · Issue #156091 · python/cpython · GitHub

Open Graph Title: Compiler crash: inlined comprehensions overflow `_PyCfgExceptStack`, bypassing the `u_nfblocks` block-nesting limit · Issue #156091 · python/cpython

X Title: Compiler crash: inlined comprehensions overflow `_PyCfgExceptStack`, bypassing the `u_nfblocks` block-nesting limit · Issue #156091 · python/cpython

Description: Crash report What happened? Compiling source with 23 or more nested list/set/dict comprehensions crashes the compiler: an assertion failure in debug builds, a segfault in release (NDEBUG) builds. Nothing is executed — compile() alone is ...

Open Graph Description: Crash report What happened? Compiling source with 23 or more nested list/set/dict comprehensions crashes the compiler: an assertion failure in debug builds, a segfault in release (NDEBUG) builds. N...

X Description: Crash report What happened? Compiling source with 23 or more nested list/set/dict comprehensions crashes the compiler: an assertion failure in debug builds, a segfault in release (NDEBUG) builds. N...

Opengraph URL: https://github.com/python/cpython/issues/156091

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Compiler crash: inlined comprehensions overflow `_PyCfgExceptStack`, bypassing the `u_nfblocks` block-nesting limit","articleBody":"# Crash report\n\n### What happened?\n\nCompiling source with 23 or more nested list/set/dict comprehensions crashes\nthe compiler: an assertion failure in debug builds, a segfault in release\n(NDEBUG) builds. Nothing is executed — `compile()` alone is enough. The input\nis ~300 bytes.\n\n## Reproduction\n\n```python\ndef src(d):\n    e = \"i for i in r\"\n    for _ in range(d - 1):\n        e = \"[\" + e + \"] for i in r\"\n    return \"x = [\" + e + \"]\"\n\ncompile(src(23), \"\u003cs>\", \"exec\")   # crashes; depth 22 compiles fine\n```\n\n## Observed behavior\n\nCliff is exactly `CO_MAXBLOCKS + 2` nested comprehensions:\n\n| Build | Crash at | Behavior |\n|---|---|---|\n| main (`20e6c2fc`), assertions on | depth 23 | `python: Python/flowgraph.c: push_except_block: Assertion 'stack->depth \u003c= CO_MAXBLOCKS' failed` |\n| main (`20e6c2fc`), `-DNDEBUG` (-O0 and -O2) | depth 23 | SIGSEGV |\n| 3.12.3 (`CO_MAXBLOCKS` = 20), distro release build | depth 22 | SIGSEGV |\n| any build | depth ≤ cliff−1 | compiles fine |\n\nRelease-build backtrace (NDEBUG, `-O0 -g`, gdb):\n\n```\nThread 1 \"fuzz_pycompile_\" received signal SIGSEGV, Segmentation fault.\n0x00005b2b9480d547 in except_stack_top (stack=0x7ba300866070) at Python/flowgraph.c:724\nwarning: Source file is more recent than executable.\n724\t    return stack->handlers[stack->depth];\n\n=== full backtrace (NDEBUG, -O0 -g, HEAD 20e6c2fc) ===\n#0  0x00005b2b9480d547 in except_stack_top (stack=0x7ba300866070) at Python/flowgraph.c:724\n#1  0x00005b2b94809f6d in label_exception_targets (entryblock=0x7ba300529d40) at Python/flowgraph.c:921\n#2  0x00005b2b94809a4d in _PyCfg_OptimizeCodeUnit (g=0x7ba300589350, consts=0x7ba3005a6a80, const_cache=0x7ba30053b140, nlocals=1, nparams=0, firstlineno=1) at Python/flowgraph.c:3798\n#3  0x00005b2b947ff534 in optimize_and_assemble_code_unit (u=0x5b2ba5b4cd30, const_cache=0x7ba30053b140, code_flags=0, filename=0x7ba30053b0b0) at Python/compile.c:1481\n#4  0x00005b2b947ff29b in _PyCompile_OptimizeAndAssemble (c=0x7ba300542f10, addNone=1) at Python/compile.c:1523\n#5  0x00005b2b947ff771 in compiler_mod (c=0x7ba300542f10, mod=0x5b2ba5b6a600) at Python/compile.c:901\n#6  0x00005b2b947ff644 in _PyAST_Compile (mod=0x5b2ba5b6a600, filename=0x7ba30053b0b0, pflags=0x7ffeec136588, optimize=0, arena=0x7ba300831b90, module=0x0) at Python/compile.c:1536\n#7  0x00005b2b9487244b in _Py_CompileString (str=0x7ffeec132580 \"x = \", '[' \u003crepeats 23 times>, \"i for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for\"..., filename=0x7ba30053b0b0, start=257, flags=0x7ffeec136588, optimize=0, module=0x0) at Python/pythonrun.c:1595\n#8  0x00005b2b948722e8 in Py_CompileStringObject (str=0x7ffeec132580 \"x = \", '[' \u003crepeats 23 times>, \"i for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for\"..., filename=0x7ba30053b0b0, start=257, flags=0x7ffeec136588, optimize=0) at Python/pythonrun.c:1561\n#9  0x00005b2b94872548 in Py_CompileStringExFlags (str=0x7ffeec132580 \"x = \", '[' \u003crepeats 23 times>, \"i for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for i in r] for\"..., filename_str=0x5b2b94b12d58 \"\u003cfuzz input>\", start=257, flags=0x7ffeec136588, optimize=0) at Python/pythonrun.c:1608\n#10 0x00005b2b9467b515 in fuzz_pycompile (data=0x5b2ba5ac08f0 \"\\002\\001\", size=307) at Modules/_xxtestfuzz/fuzzer.c:564\n#11 0x00005b2b9467b342 in _run_fuzz (data=0x5b2ba5ac08f0 \"\\002\\001\", size=307, fuzzer=0x5b2b9467b370 \u003cfuzz_pycompile>) at Modules/_xxtestfuzz/fuzzer.c:583\n#12 0x00005b2b9467b30b in LLVMFuzzerTestOneInput (data=0x5b2ba5ac08f0 \"\\002\\001\", size=307) at Modules/_xxtestfuzz/fuzzer.c:724\n#13 0x00005b2b94638813 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) ()\n#14 0x00005b2b94622691 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) ()\n#15 0x00005b2b94628358 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) ()\n#16 0x00005b2b94651973 in main ()\n#17 0x00007ba30062a1ca in __libc_start_call_main (main=main@entry=0x5b2b94651950 \u003cmain>, argc=argc@entry=2, argv=argv@entry=0x7ffeec136df8) at ../sysdeps/nptl/libc_start_call_main.h:58\n#18 0x00007ba30062a28b in __libc_start_main_impl (main=0x5b2b94651950 \u003cmain>, argc=2, argv=0x7ffeec136df8, init=\u003coptimized out>, fini=\u003coptimized out>, rtld_fini=\u003coptimized out>, stack_end=0x7ffeec136de8) at ../csu/libc-start.c:360\n#19 0x00005b2b9461d035 in _start ()\n```\n\nThe faulting address equals `&handlers[0] + depth * 8`, where `depth` is a\ncorrupted value (see below), ~1 GB away from the struct.\n\n## Root cause\n\nSince PEP 709 (3.12), non-generator comprehensions are inlined into the\nenclosing scope. Each inlined comprehension emits one \"virtual try/finally\"\n(`SETUP_FINALLY` cleanup to restore shadowed outer locals) — but it is\ndeliberately not counted as an fblock, in `codegen_push_inlined_comprehension_locals`\n(Python/codegen.c):\n\n```c\n// no need to push an fblock for this \"virtual\" try/finally; there can't\n// be return/continue/break inside a comprehension\n```\n\nSo the only static nesting guard, `u_nfblocks >= CO_MAXBLOCKS → \"too many\nstatically nested blocks\"` (Python/compile.c), never sees these blocks.\n\nThe backend then trusts the frontend limit and uses a fixed-size stack in\nPython/flowgraph.c:\n\n```c\nstruct _PyCfgExceptStack {\n    basicblock *handlers[CO_MAXBLOCKS+2];\n    int depth;\n};\n```\n\nThe N-th inlined comprehension pushes the N-th block; at nesting depth\n`CO_MAXBLOCKS + 2` the push writes one slot past the array.\n\n- **Assertions on:** `assert(stack->depth \u003c= CO_MAXBLOCKS)` in\n  `push_except_block` fires → abort.\n- **NDEBUG:** the out-of-bounds store writes `handlers[CO_MAXBLOCKS+2]`,\n  which by struct layout is exactly the `depth` field\n  (`&handlers[CO_MAXBLOCKS+2] == &depth`, confirmed with gdb). `depth` is\n  clobbered with the low 32 bits of a `basicblock *`; the next\n  `except_stack_top` uses it as an index into `handlers[]` → wild read →\n  deterministic SIGSEGV.\n\n## Suggested fix\n\nCount the inlined-comprehension cleanup blocks toward `u_nfblocks` so the\nexisting `\"too many statically nested blocks\"` SyntaxError fires (consistent\nwith gh-118348), or make `_PyCfgExceptStack` dynamically sized / bounds-checked.\n\n## Environment\n\n- CPython main `20e6c2fc7c174342214d561845419c4030f8638f` (2026-08-19)\n- Ubuntu 24.04 \n\n\n### CPython versions tested on:\n\n3.15, CPython main branch, 3.16, 3.14, 3.13, 3.12\n\n### Operating systems tested on:\n\nLinux\n\n### Output from running 'python -VV' on the command line:\n\n_No response_\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-156957\n* gh-156992\n* gh-156993\n* gh-157050\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/kid-lxy","@type":"Person","name":"kid-lxy"},"datePublished":"2026-08-20T09:43:01Z","url":"https://github.com/python/cpython/issues/156091"}

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/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:a2d4c9a7-0049-592c-573e-fbf806e3ffb3
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCE32:25F5AB:3B164:49AF6:6B01FA3C
html-safe-nonce2bd1d41487c5d3a298c45036ad182e600f6d4cedae82dd3a3386d674d0a382e1
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRTMyOjI1RjVBQjozQjE2NDo0OUFGNjo2QjAxRkEzQyIsInZpc2l0b3JfaWQiOiI0NTY3ODg2MTY3MDc2MzcxMDA0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac7a94b9d9262e1669ff09647eb99ec23b9ce9ff39d5520735c4c3d0346250ec9a
hovercard-subject-tagissue:5202016421
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/156091/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d21d85a85628fd11a655924e809dd425eac35cd3402c9ac58b6ba6b26fd2927f/python/cpython/issues/156091
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d21d85a85628fd11a655924e809dd425eac35cd3402c9ac58b6ba6b26fd2927f/python/cpython/issues/156091
og:image:altCrash report What happened? Compiling source with 23 or more nested list/set/dict comprehensions crashes the compiler: an assertion failure in debug builds, a segfault in release (NDEBUG) builds. N...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamekid-lxy
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/156091#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F156091
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%2Fpython%2Fcpython%2Fissues%2F156091
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/156091
Reloadhttps://github.com/python/cpython/issues/156091
Reloadhttps://github.com/python/cpython/issues/156091
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/156091
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/156091
#156957https://github.com/python/cpython/pull/156957
Compiler crash: inlined comprehensions overflow _PyCfgExceptStack, bypassing the u_nfblocks block-nesting limithttps://github.com/python/cpython/issues/156091#top
#156957https://github.com/python/cpython/pull/156957
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
https://github.com/kid-lxy
kid-lxyhttps://github.com/kid-lxy
on Aug 20, 2026https://github.com/python/cpython/issues/156091#issue-5202016421
gh-118348https://github.com/python/cpython/pull/118348
gh-156091: Fix crash compiling deeply nested inlined comprehensions #156957https://github.com/python/cpython/pull/156957
[3.15] gh-156091: Fix crash compiling deeply nested inlined comprehensions (GH-156957) #156992https://github.com/python/cpython/pull/156992
[3.14] gh-156091: Fix crash compiling deeply nested inlined comprehensions (GH-156957) #156993https://github.com/python/cpython/pull/156993
[3.13] gh-156091: Fix crash compiling deeply nested inlined comprehensions (GH-156957) #157050https://github.com/python/cpython/pull/157050
kid-lxyhttps://github.com/kid-lxy
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
on Aug 20, 2026https://github.com/python/cpython/issues/156091#event-29735115102
picnixzhttps://github.com/picnixz
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
on Sep 4, 2026https://github.com/python/cpython/issues/156091#event-30575257437
iritkatrielhttps://github.com/iritkatriel
on Sep 5, 2026https://github.com/python/cpython/issues/156091#event-30611414261
Merge branch 'main' into pythongh-156091https://github.com/iritkatriel/cpython/commit/1385ed421a238b834bba3b92aa2adff7de619bde
pythongh-156091https://github.com/python/cpython/issues/156091
1385ed4https://github.com/iritkatriel/cpython/commit/1385ed421a238b834bba3b92aa2adff7de619bde
iritkatrielhttps://github.com/iritkatriel
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#156957https://github.com/python/cpython/pull/156957
on Sep 5, 2026https://github.com/python/cpython/issues/156091#event-30612237554
iritkatrielhttps://github.com/iritkatriel
on Sep 5, 2026https://github.com/python/cpython/issues/156091#event-30612237623
gh-156091: Fix crash compiling deeply nested inlined comprehensions (#…https://github.com/python/cpython/commit/14a93f4d91edf767e7b35413127cfcd6a2806983
gh-156091https://github.com/python/cpython/issues/156091
#…https://github.com/python/cpython/pull/156957
14a93f4https://github.com/python/cpython/commit/14a93f4d91edf767e7b35413127cfcd6a2806983
[3.14] gh-156091: Fix crash compiling deeply nested inlined comprehen…https://github.com/python/cpython/commit/dd36d014da20f6217f0ae729450dd79745545927
gh-156091https://github.com/python/cpython/issues/156091
dd36d01https://github.com/python/cpython/commit/dd36d014da20f6217f0ae729450dd79745545927
clin1234https://github.com/clin1234
on Sep 12, 2026https://github.com/python/cpython/issues/156091#event-31023917604
pythongh-156091: Fix crash compiling deeply nested inlined comprehens…https://github.com/clin1234/cpython/commit/86c03f365c71eb2c7d2bc32c051ca91d241bdbdf
pythongh-156091https://github.com/python/cpython/issues/156091
86c03f3https://github.com/clin1234/cpython/commit/86c03f365c71eb2c7d2bc32c051ca91d241bdbdf
iritkatrielhttps://github.com/iritkatriel
on Sep 17, 2026https://github.com/python/cpython/issues/156091#event-31340521424
[3.13] gh-156091: Fix crash compiling deeply nested inlined comprehen…https://github.com/python/cpython/commit/d7657d0e1850f90624ea8be63d6fdb5a8dd3e497
gh-156091https://github.com/python/cpython/issues/156091
d7657d0https://github.com/python/cpython/commit/d7657d0e1850f90624ea8be63d6fdb5a8dd3e497
serhiy-storchakahttps://github.com/serhiy-storchaka
on Oct 10, 2026https://github.com/python/cpython/issues/156091#event-32936996822
[3.15] gh-156091: Fix crash compiling deeply nested inlined comprehen…https://github.com/python/cpython/commit/845fb344be66f0ec0428a9989905f20fd2d4087c
gh-156091https://github.com/python/cpython/issues/156091
845fb34https://github.com/python/cpython/commit/845fb344be66f0ec0428a9989905f20fd2d4087c
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/156091
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/156091
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
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.