Title: gh-151842: Make _PyXI_FreeExcInfo NULL-safe to fix crash on capture_exception() OOM (OOM-0031) by amruthamodela06 · Pull Request #151843 · python/cpython · GitHub
Open Graph Title: gh-151842: Make _PyXI_FreeExcInfo NULL-safe to fix crash on capture_exception() OOM (OOM-0031) by amruthamodela06 · Pull Request #151843 · python/cpython
X Title: gh-151842: Make _PyXI_FreeExcInfo NULL-safe to fix crash on capture_exception() OOM (OOM-0031) by amruthamodela06 · Pull Request #151843 · python/cpython
Description: Closes #151842 Summary _interpreters.capture_exception() builds a _PyXI_excinfo via _PyXI_NewExcInfo(). Under memory pressure that allocation can fail and return NULL. The cleanup path in _interpreters_capture_exception_impl (Modules/_interpretersmodule.c:1544) then unconditionally calls _PyXI_FreeExcInfo(info) with info == NULL. _PyXI_FreeExcInfo has no NULL guard, so _PyXI_excinfo_clear → _excinfo_clear_type dereferences &NULL->type (offset 0) at Python/crossinterp.c:1319 → SIGSEGV. This reproduces on all build configurations (a NULL dereference, not a debug-only assert). Part of #151763 (OOM umbrella, OOM-0031). Reproducer import faulthandler, _interpreters faulthandler.enable() from _testcapi import set_nomemory, remove_mem_hooks for start in range(0, 40): try: set_nomemory(start, 0) try: _interpreters.capture_exception(Exception()) finally: remove_mem_hooks() except BaseException: pass finally: try: remove_mem_hooks() except Exception: pass Backtrace #0 _excinfo_clear_type Python/crossinterp.c:1319 # info == 0x0 -> offset-0 deref #1 _PyXI_excinfo_clear Python/crossinterp.c:1374 #2 _PyXI_FreeExcInfo Python/crossinterp.c:1712 # called with info == NULL, no guard #3 _interpreters_capture_exception_impl Modules/_interpretersmodule.c:1544 Fix Make _PyXI_FreeExcInfo NULL-safe, matching the surrounding PyMem_RawFree(NULL) idiom (and Py_XDECREF, free(), etc.). This is more defensive than guarding only the one call site, since _PyXI_FreeExcInfo is part of the cross-interpreter exception ABI and any future caller would otherwise have the same hazard. void _PyXI_FreeExcInfo(_PyXI_excinfo *info) { if (info == NULL) { return; } _PyXI_excinfo_clear(info); PyMem_RawFree(info); } Verification test_interpreters passes on the rebuilt binary (no regression in the success path). Per the discussion in #151773 (same umbrella), no OOM-injection regression test is added — those tests rely on internal allocation counts that need re-tuning across implementation changes. The fix should be verified by running the reproducer on a debug+ASan build. Issue: gh-151842
Open Graph Description: Closes #151842 Summary _interpreters.capture_exception() builds a _PyXI_excinfo via _PyXI_NewExcInfo(). Under memory pressure that allocation can fail and return NULL. The cleanup path in _interpre...
X Description: Closes #151842 Summary _interpreters.capture_exception() builds a _PyXI_excinfo via _PyXI_NewExcInfo(). Under memory pressure that allocation can fail and return NULL. The cleanup path in _interpre...
Opengraph URL: https://github.com/python/cpython/pull/151843
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:cabc4e64-764e-1d9c-02c9-d17c74ac0211 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9250:6E56C:B45B2D:F08599:6A54055D |
| html-safe-nonce | f17e951c26d66ca53517cb08c3e405eefb5df7c2bbe48dfc23fec42b4d220d3c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MjUwOjZFNTZDOkI0NUIyRDpGMDg1OTk6NkE1NDA1NUQiLCJ2aXNpdG9yX2lkIjoiNzQ3NzA3NzA3MjM5NTEwOTcyNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 38037c0585c6170b8da75e407f3772dec08a462a91e5809dd554d0bade7952b9 |
| hovercard-subject-tag | pull_request:3906743759 |
| 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/151843/files |
| twitter:image | https://avatars.githubusercontent.com/u/213800128?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/213800128?s=400&v=4 |
| og:image:alt | Closes #151842 Summary _interpreters.capture_exception() builds a _PyXI_excinfo via _PyXI_NewExcInfo(). Under memory pressure that allocation can fail and return NULL. The cleanup path in _interpre... |
| 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