Title: Allocation failure while decoding a string literal's escapes returns NULL without an exception set · Issue #158309 · python/cpython · GitHub
Open Graph Title: Allocation failure while decoding a string literal's escapes returns NULL without an exception set · Issue #158309 · python/cpython
X Title: Allocation failure while decoding a string literal's escapes returns NULL without an exception set · Issue #158309 · python/cpython
Description: Crash report What happened? Summary When the buffer allocation in decode_unicode_with_escapes() fails while compiling a string literal that contains a backslash escape, the function returns NULL without setting an exception. In a debug b...
Open Graph Description: Crash report What happened? Summary When the buffer allocation in decode_unicode_with_escapes() fails while compiling a string literal that contains a backslash escape, the function returns NULL wi...
X Description: Crash report What happened? Summary When the buffer allocation in decode_unicode_with_escapes() fails while compiling a string literal that contains a backslash escape, the function returns NULL wi...
Opengraph URL: https://github.com/python/cpython/issues/158309
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allocation failure while decoding a string literal's escapes returns NULL without an exception set","articleBody":"# Crash report\n\n### What happened?\n\n### Summary\n\nWhen the buffer allocation in `decode_unicode_with_escapes()` fails while compiling a string literal that contains a backslash escape, the function returns `NULL` without setting an exception. In a debug build this aborts on `assert(PyErr_Occurred())` in `_Pypegen_raise_decode_error()`. In a release build, `compile()` raises `SyntaxError: invalid syntax` for valid source instead of `MemoryError`.\n\n### Reproduction Code\n\n\n```python\nimport ast, _testcapi\n\nfor n in range(1, 200):\n _testcapi.set_nomemory(n, n + 1)\n try:\n compile(\"x = '\\\\n'\", \"\u003cstring>\", \"exec\", ast.PyCF_ONLY_AST)\n except MemoryError:\n pass\n finally:\n _testcapi.remove_mem_hooks()\nprint(\"done\")\n```\n\n### Actual Behavior\n\nDebug build (`--with-pydebug`):\n\n```text\npython: Parser/pegen_errors.c:87: _Pypegen_raise_decode_error: Assertion `PyErr_Occurred()' failed.\nAborted (core dumped)\n```\n\nRelease build:\n\n```text\nTraceback (most recent call last):\n File \"nomem_repro.py\", line 6, in \u003cmodule>\n compile(\"x = '\\\\n'\", \"\u003cstring>\", \"exec\", ast.PyCF_ONLY_AST)\n ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"\u003cstring>\", line 1\n x = '\\n'\n ^^^^\nSyntaxError: invalid syntax\n```\n\n\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\n_No response_\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-158311\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/lpyu001","@type":"Person","name":"lpyu001"},"datePublished":"2026-09-28T02:27:46Z","url":"https://github.com/python/cpython/issues/158309"}
| 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:b2597e38-bc9a-2171-1ad9-db6e34c9d161 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CB00:23E48:36CBB:4440E:6B01FA17 |
| html-safe-nonce | 19dd6d8cd0a05a2306e7b1a08171e8c98195cabc0f368f53d09caeb3c87aa62a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjAwOjIzRTQ4OjM2Q0JCOjQ0NDBFOjZCMDFGQTE3IiwidmlzaXRvcl9pZCI6IjQ1MDc5ODUyNzE4MTEzNDA4MjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 42ffcdd900f1b782763bbe480da3bb29b11f49e85de30f5694fc5d7ae08097c9 |
| hovercard-subject-tag | issue:5608440412 |
| 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/158309/issue_layout |
| twitter:image | https://opengraph.githubassets.com/23d3cd7c7dea5f456410f9081b4f6ab54fc0f5d0c052f391a8f4d5cb020781ea/python/cpython/issues/158309 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/23d3cd7c7dea5f456410f9081b4f6ab54fc0f5d0c052f391a8f4d5cb020781ea/python/cpython/issues/158309 |
| og:image:alt | Crash report What happened? Summary When the buffer allocation in decode_unicode_with_escapes() fails while compiling a string literal that contains a backslash escape, the function returns NULL wi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lpyu001 |
| 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