Title: Crash in genericaliasobject.c when tuple_extend() fails under allocation failure · Issue #155053 · python/cpython · GitHub
Open Graph Title: Crash in genericaliasobject.c when tuple_extend() fails under allocation failure · Issue #155053 · python/cpython
X Title: Crash in genericaliasobject.c when tuple_extend() fails under allocation failure · Issue #155053 · python/cpython
Description: Crash report What happened? While investigating allocation-failure paths in Objects/genericaliasobject.c, I found a NULL dereference in subs_tvars(). When tuple_extend() fails, it returns -1 after _PyTuple_Resize() fails. _PyTuple_Resize...
Open Graph Description: Crash report What happened? While investigating allocation-failure paths in Objects/genericaliasobject.c, I found a NULL dereference in subs_tvars(). When tuple_extend() fails, it returns -1 after ...
X Description: Crash report What happened? While investigating allocation-failure paths in Objects/genericaliasobject.c, I found a NULL dereference in subs_tvars(). When tuple_extend() fails, it returns -1 after ...
Opengraph URL: https://github.com/python/cpython/issues/155053
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Crash in genericaliasobject.c when tuple_extend() fails under allocation failure","articleBody":"# Crash report\n\n### What happened?\n\nWhile investigating allocation-failure paths in `Objects/genericaliasobject.c`, I found a NULL dereference in `subs_tvars()`.\n\nWhen `tuple_extend()` fails, it returns `-1` after `_PyTuple_Resize()` fails. `_PyTuple_Resize()` clears its out-parameter (`*pv = NULL`) on failure, so `subargs` is guaranteed to be `NULL`.\n\nHowever, `subs_tvars()` unconditionally calls:\n\n```c\nif (j \u003c 0) {\n Py_DECREF(subparams);\n Py_DECREF(subargs);\n return NULL;\n}\n```\n\nAs a result, `Py_DECREF(subargs)` dereferences a NULL pointer and crashes the interpreter instead of propagating the `MemoryError`.\n\n### Reproducer\n\nA debug build with `_testcapi` is required.\n\n```python\nimport _testcapi\nfrom typing import TypeVarTuple\n\nTs = TypeVarTuple(\"Ts\")\nalias = dict[str, tuple[*Ts]]\nkey = (int, str)\n\n_testcapi.set_nomemory(24, 25)\ntry:\n alias[key]\nfinally:\n _testcapi.remove_mem_hooks()\n```\n\nThe exact allocation index may vary between builds, so sweeping a range of indices is recommended.\n\n### Observed result\n\nASan reports:\n\n```text\nAddressSanitizer: SEGV on unknown address 0x000000000000\n\n#0 _Py_IsImmortal\n#1 Py_DECREF\n#2 subs_tvars (Objects/genericaliasobject.c)\n#3 _Py_subs_parameters\n#4 ga_getitem\n```\n\n### Root cause\n\n`tuple_extend()` immediately returns `-1` when `_PyTuple_Resize()` fails. `_PyTuple_Resize()` sets its out-parameter to `NULL` on failure, so `subargs` is guaranteed to be `NULL` when control reaches the error path. Calling `Py_DECREF(subargs)` therefore dereferences a NULL pointer.\n\nThe issue appears related to gh-148222, which removed the same `Py_DECREF()` pattern from `_Py_make_parameters()` after `_PyTuple_Resize()` failure, but this analogous path in `subs_tvars()` remained unchanged.\n\nRemoving `Py_DECREF(subargs);` causes the reproducer to raise `MemoryError` instead of crashing.\n\n### CPython versions tested on:\n\nCPython 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/investigate-genericalias-oom-null-decref-dirty:7ce7f0bd851, Aug 1 2026) [GCC 13.3.0]\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-155055\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/BHUVANSH855","@type":"Person","name":"BHUVANSH855"},"datePublished":"2026-08-01T19:10:04Z","url":"https://github.com/python/cpython/issues/155053"}
| 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:37ad8d7a-a264-0147-5c64-e6b6d69baebd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9254:4D9F2:1DD5294:2779F2C:6B0231BF |
| html-safe-nonce | 37c2afb1f62b7f1501350cc73f41b5ec4af66043d323d269f5033e75e542df97 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MjU0OjREOUYyOjFERDUyOTQ6Mjc3OUYyQzo2QjAyMzFCRiIsInZpc2l0b3JfaWQiOiI3NDk3Njk4NDg1OTk5OTA3MjYzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 513f8fd9fbbe36ee2962b0126a0eb3c026d93c43b30c4b1f9d297f2075b73daf |
| hovercard-subject-tag | issue:5038594609 |
| 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/155053/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c630285123f41d0952eff3f3a87648cc7d5b3bcb1a2ecbffe908a869a984d1b7/python/cpython/issues/155053 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c630285123f41d0952eff3f3a87648cc7d5b3bcb1a2ecbffe908a869a984d1b7/python/cpython/issues/155053 |
| og:image:alt | Crash report What happened? While investigating allocation-failure paths in Objects/genericaliasobject.c, I found a NULL dereference in subs_tvars(). When tuple_extend() fails, it returns -1 after ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | BHUVANSH855 |
| 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