Title: gh-151763: Fix OOM-0013 crash when the parser or compiler fails to allocate by tonghuaroot · Pull Request #151968 · python/cpython · GitHub
Open Graph Title: gh-151763: Fix OOM-0013 crash when the parser or compiler fails to allocate by tonghuaroot · Pull Request #151968 · python/cpython
X Title: gh-151763: Fix OOM-0013 crash when the parser or compiler fails to allocate by tonghuaroot · Pull Request #151968 · python/cpython
Description: This fixes OOM-0013 from the gh-151763 umbrella. compile(), exec(), eval() and ast.parse() can return NULL without setting an exception when an allocation fails, breaking the result/error contract every consumer relies on and crashing on the assertion that checks it (for example the (res != NULL) ^ (PyErr_Occurred()) check reached from the evaluation loop, and assert(!PyErr_Occurred()) at the top of _PyAST_Validate). Three points returned NULL silently under a failed allocation: new_compiler() returned NULL without calling PyErr_NoMemory() when its initial PyMem_Calloc failed -- the dominant compile()/exec()/eval() path. _PyPegen_run_parser() could return a valid result while leaving a stale exception pending. The tokenizer-init helpers could fail silently. Setting the error indicator at each point makes a failed allocation surface as MemoryError instead of a NULL-without-exception crash. Reproduction (debug build, _testcapi.set_nomemory) ast.parse(...) under set_nomemory aborted with "a function returned NULL without setting an exception"; a clean MemoryError is raised after the fix. compile() / exec() / eval() under set_nomemory aborted at the result/error contract assertion; clean after the fix. Reverting either guard reproduces the corresponding abort (negative control). No test is added, following the convention for these OOM crash fixes.
Open Graph Description: This fixes OOM-0013 from the gh-151763 umbrella. compile(), exec(), eval() and ast.parse() can return NULL without setting an exception when an allocation fails, breaking the result/error contract ...
X Description: This fixes OOM-0013 from the gh-151763 umbrella. compile(), exec(), eval() and ast.parse() can return NULL without setting an exception when an allocation fails, breaking the result/error contract ...
Opengraph URL: https://github.com/python/cpython/pull/151968
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:5abae85a-2211-7067-cedd-b2e7558bb6fb |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D89E:260009:1CE38AB:26713E8:6A52D78B |
| html-safe-nonce | d593dd86c839447671f9ae444f659fbf2368f99c0ef607cdc7f0afa13e19262d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODlFOjI2MDAwOToxQ0UzOEFCOjI2NzEzRTg6NkE1MkQ3OEIiLCJ2aXNpdG9yX2lkIjoiNTMwMzIzODMwMjQ3NTkzMzU3OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fb079c60043d475ec7058d7cf612d1552400ad4f1cbf477655e29dccd9d468a1 |
| hovercard-subject-tag | pull_request:3917905495 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/python/cpython/pull/151968/files |
| twitter:image | https://avatars.githubusercontent.com/u/23011166?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/23011166?s=400&v=4 |
| og:image:alt | This fixes OOM-0013 from the gh-151763 umbrella. compile(), exec(), eval() and ast.parse() can return NULL without setting an exception when an allocation fails, breaking the result/error contract ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width