Title: Double free corruption when allocation failures occur in assemble_init · Issue #151112 · python/cpython · GitHub
Open Graph Title: Double free corruption when allocation failures occur in assemble_init · Issue #151112 · python/cpython
X Title: Double free corruption when allocation failures occur in assemble_init · Issue #151112 · python/cpython
Description: Crash report What happened? import _testcapi compile("pass", "
Open Graph Description: Crash report What happened? import _testcapi compile("pass", "
X Description: Crash report What happened? import _testcapi compile("pass", "<warmup>", "single") _testcapi.set_nomemory(64, 65) try: compile("pass", "<trigge...
Opengraph URL: https://github.com/python/cpython/issues/151112
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Double free corruption when allocation failures occur in assemble_init","articleBody":"# Crash report\n\n### What happened?\n\n```python\nimport _testcapi\n\ncompile(\"pass\", \"\u003cwarmup>\", \"single\")\n_testcapi.set_nomemory(64, 65)\ntry:\n compile(\"pass\", \"\u003ctrigger>\", \"single\")\nexcept MemoryError:\n pass\nfirst = bytes(128)\nsecond = bytes(128)\n```\n```\nJob 1, './python.exe reproduce_assemble…' terminated by signal SIGSEGV (Address boundary error)\n```\nNote, this reproducer only works if the allocation sizes are exactly the same as on my mac! the nomemory values may need tweaking.\n\nThe chain is:\n - `_PyAssemble_MakeCodeObject` is called\n - this calls assemble_emit which calls `RETURN_IF_ERROR(assemble_init(a, first_lineno));` passing the assembler by ref as an argument.\n - An allocation failure happens in `assemble_init`, when allocating the linetable or the except table.\n - `assemble_init` cleans up by decreffing all members, BUT the assembler fields are left populated with the old pointers, and the caller has the assembler reference.\n - `assemble_emit` sees the error code and returns to `_PyAssemble_MakeCodeObject`\n - The result != SUCCESS, so makecode isn't called, but `assemble_free` IS called, causing a double free of at least `a->a_bytecode`.\n\nThe error manifests itself as heap corruption from the double free.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nmacOS\n\n### Output from running 'python -VV' on the command line:\n\nPython 3.16.0a0 (heads/main-dirty:f051c68923b, Jun 8 2026, 16:26:15) [Clang 21.0.0 (clang-2100.1.1.101)]\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-151142\n* gh-151153\n* gh-151205\n* gh-151206\n* gh-151207\n* gh-151234\n* gh-151313\n* gh-151314\n* gh-151315\n* gh-151350\n* gh-151351\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/stestagg","@type":"Person","name":"stestagg"},"datePublished":"2026-06-08T20:44:05Z","url":"https://github.com/python/cpython/issues/151112"}
| 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:137870b3-2058-6c55-c9ed-55346eaf281f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EAA2:317608:3B3FED6:4B071D5:6B01FACC |
| html-safe-nonce | bc9fbd1abf7a4777f233285a3b8287143b9983bd34e5a07b0d953d7c6b7e6f55 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQUEyOjMxNzYwODozQjNGRUQ2OjRCMDcxRDU6NkIwMUZBQ0MiLCJ2aXNpdG9yX2lkIjoiNTAyNDMyNjkxNDQ0NjMyNjQ3NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 651a96a1461be579ab80a58fe0ea3d5748e0b0a9a9aaa2117ab1adb87007ef96 |
| hovercard-subject-tag | issue:4616500841 |
| 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/151112/issue_layout |
| twitter:image | https://opengraph.githubassets.com/88b07c0ef0d3d2515e63ca19c8f1828c648beef7326fb9a7d64929cc061b9e4e/python/cpython/issues/151112 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/88b07c0ef0d3d2515e63ca19c8f1828c648beef7326fb9a7d64929cc061b9e4e/python/cpython/issues/151112 |
| og:image:alt | Crash report What happened? import _testcapi compile("pass", " |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | stestagg |
| 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