Title: _Py_make_parameters recurses without a guard: a self-referential/deeply-nested generic-alias arg crashes the interpreter · Issue #154275 · python/cpython · GitHub
Open Graph Title: _Py_make_parameters recurses without a guard: a self-referential/deeply-nested generic-alias arg crashes the interpreter · Issue #154275 · python/cpython
X Title: _Py_make_parameters recurses without a guard: a self-referential/deeply-nested generic-alias arg crashes the interpreter · Issue #154275 · python/cpython
Description: Crash report What happened? Computing __parameters__ of a generic alias whose argument is a self-referential (or merely very deeply nested) list/tuple crashes the interpreter with a C-stack overflow. _Py_make_parameters (Objects/generica...
Open Graph Description: Crash report What happened? Computing __parameters__ of a generic alias whose argument is a self-referential (or merely very deeply nested) list/tuple crashes the interpreter with a C-stack overflo...
X Description: Crash report What happened? Computing __parameters__ of a generic alias whose argument is a self-referential (or merely very deeply nested) list/tuple crashes the interpreter with a C-stack overflo...
Opengraph URL: https://github.com/python/cpython/issues/154275
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"_Py_make_parameters recurses without a guard: a self-referential/deeply-nested generic-alias arg crashes the interpreter","articleBody":"# Crash report\n\n### What happened?\n\nComputing `__parameters__` of a generic alias whose argument is a self-referential (or merely very deeply nested) `list`/`tuple` crashes the interpreter with a C-stack overflow. `_Py_make_parameters` (`Objects/genericaliasobject.c`) recurses into nested `list`/`tuple` args without any recursion guard (`Py_EnterRecursiveCall`), so a cyclic argument recurses forever.\n\nMinimal reproducer:\n\n```python\nL = []\nL.append(L) # L = [L], self-referential\nlist[L].__parameters__ # SIGSEGV\n```\n\n`list[L]` on its own is fine — `__parameters__` is computed lazily, and the crash is in that computation (anything that triggers it — using the alias as a base class, `typing.get_args()`, etc. — crashes the same way).\n\nA non-cyclic but deeply nested list crashes it too, which shows the path is simply unguarded rather than something cycle-specific:\n\n```python\nx = [0]\nfor _ in range(500_000):\n x = [x]\nlist[x].__parameters__ # SIGSEGV (C stack overflow)\n```\n\nBacktrace (debug build); the interpreter dies in `_Py_make_parameters` self-recursion at `genericaliasobject.c:231`:\n\n```\n#0 gc_alloc Python/gc.c:2013 \u003c- SIGSEGV at the stack guard page\n#1 _PyObject_GC_NewVar Python/gc.c:2055\n#2 tuple_alloc Objects/tupleobject.c:57\n#3 PyTuple_FromArray Objects/tupleobject.c:442\n#4 PyList_AsTuple Objects/listobject.c:3269\n#5 _Py_make_parameters Objects/genericaliasobject.c:192\n#6 _Py_make_parameters Objects/genericaliasobject.c:231 \u003c- unguarded recursion\n#7 _Py_make_parameters Objects/genericaliasobject.c:231\n ... (repeats until the C stack overflows) ...\n```\n\n### Analysis\n\n`_Py_make_parameters` collects type parameters from an alias's arguments. For an argument that is a `list`/`tuple` with no `__parameters__`, it recurses into it:\n\n```c\nif (!subparams && (PyTuple_Check(t) || PyList_Check(t))) {\n // Recursively call _Py_make_parameters for lists/tuples and\n // add the results to the current parameters.\n subparams = _Py_make_parameters(t); // Objects/genericaliasobject.c:231\n ...\n}\n```\n\nThere is no `Py_EnterRecursiveCall` / `Py_LeaveRecursiveCall` in this function — nor anywhere in `genericaliasobject.c` — so a self-referential argument recurses without bound and overflows the C stack (SIGSEGV) instead of raising `RecursionError`.\n\nFix direction: wrap the recursive descent in `Py_EnterRecursiveCall(...)` / `Py_LeaveRecursiveCall()`, as other recursive C paths do, so the overflow becomes a catchable `RecursionError`.\n\nNot free-threading- or JIT-specific: reproduces on GIL and free-threaded, release and debug builds.\n\n_(Found via fuzzing with [fusil](https://github.com/devdanzin/fusil); the same reproducer also crashes RustPython, whose `make_parameters_from_slice` has the identical unguarded recursion. Reduced and reviewed by hand; draft prepared with Claude Code.)_\n\n\n### CPython versions tested on:\n\n3.14, CPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n### Output from running 'python -VV' on the command line:\n\nPython 3.16.0a0 (heads/main:a1d580430c8, Jul 18 2026, 20:16:15) [Clang 21.1.8 (6ubuntu1)]\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-154277\n* gh-154306\n* gh-154339\n* gh-154340\n* gh-154341\n* gh-154342\n* gh-154343\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/devdanzin","@type":"Person","name":"devdanzin"},"datePublished":"2026-07-20T16:34:38Z","url":"https://github.com/python/cpython/issues/154275"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7466e5b4-8348-4a7e-9563-2f67e2e97e67 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C46:B53AF:395480B:4C3947B:6B021B48 |
| html-safe-nonce | dc8cd3d0d40c5c71cccf1ba661e27a276cdd233c3b1d77e271f89ff77d78b051 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzQ2OkI1M0FGOjM5NTQ4MEI6NEMzOTQ3Qjo2QjAyMUI0OCIsInZpc2l0b3JfaWQiOiI0OTQ5MjQwNjQyNjE1MjUzODMyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 379bbe2b5b0c6c0ecf393dc15a49e4537657da3bd757710465a0f29e72a17487 |
| hovercard-subject-tag | issue:4930973473 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/154275/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6fe76003c9a830a63c54bd51118d0b7c27bb6d468a521e21fe792b8f1bbe000e/python/cpython/issues/154275 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6fe76003c9a830a63c54bd51118d0b7c27bb6d468a521e21fe792b8f1bbe000e/python/cpython/issues/154275 |
| og:image:alt | Crash report What happened? Computing __parameters__ of a generic alias whose argument is a self-referential (or merely very deeply nested) list/tuple crashes the interpreter with a C-stack overflo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | devdanzin |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width