Title: gh-151763: Fix OOM-0014 crash in _interpchannels._channel_id by zainnadeem786 · Pull Request #151902 · python/cpython · GitHub
Open Graph Title: gh-151763: Fix OOM-0014 crash in _interpchannels._channel_id by zainnadeem786 · Pull Request #151902 · python/cpython
X Title: gh-151763: Fix OOM-0014 crash in _interpchannels._channel_id by zainnadeem786 · Pull Request #151902 · python/cpython
Description: Summary This PR addresses OOM-0014 from gh-151763. It fixes a crash in _interpchannels._channel_id() when memory allocation fails while looking up module state. Issue channelsmod__channel_id() obtains the owning module with: PyObject *mod = get_module_from_owned_type(cls); assert(mod == self); Py_DECREF(mod); get_module_from_owned_type() eventually calls _get_current_module(), which allocates the module name using: PyUnicode_FromString(MODULE_NAME_STR) Under out-of-memory conditions this allocation can fail and return NULL with a pending MemoryError. Before this change, channelsmod__channel_id() assumed the helper could never fail. As a result: Debug builds abort at: assert(mod == self); because mod == NULL. Release builds compile out the assertion and continue to: Py_DECREF(mod); which dereferences NULL and results in an access violation / segmentation fault. Root Cause The helper get_module_from_owned_type(cls) returns a new reference on success but can legitimately return NULL when _get_current_module() fails during module-name allocation. channelsmod__channel_id() did not check for that failure before using the returned object. Fix Add an explicit NULL check immediately after obtaining the module: PyObject *mod = get_module_from_owned_type(cls); if (mod == NULL) { return NULL; } assert(mod == self); Py_DECREF(mod); This preserves the existing invariant check while correctly propagating the pending MemoryError instead of aborting or crashing. Validation I reproduced the issue locally on both debug and release builds. Before the fix Debug build: Assertion failed: mod == self Modules/_interpchannelsmodule.c Fatal Python error: Aborted Release build: Windows fatal exception: access violation After the fix The same OOM path now returns a clean MemoryError and no longer aborts or crashes. Regression Test Added a focused subprocess regression test in: Lib/test/test__interpchannels.py The test: uses _testcapi.set_nomemory(0, 1) exercises _interpchannels._channel_id(0) verifies that the subprocess exits normally verifies that MemoryError is propagated instead of aborting or crashing The test is skipped under Py_TRACE_REFS, matching the existing limitations of _testcapi.set_nomemory(). Tests Executed: PCbuild/amd64/python_d.exe -m test test__interpchannels Result: == Tests result: SUCCESS == 1 test OK. Total tests: run=74 skipped=5 I also verified: git diff --check which reports no patch formatting issues (only existing LF/CRLF working-copy warnings). NEWS Added a NEWS fragment describing the crash fix and MemoryError propagation. Addresses OOM-0014 from gh-151763.
Open Graph Description: Summary This PR addresses OOM-0014 from gh-151763. It fixes a crash in _interpchannels._channel_id() when memory allocation fails while looking up module state. Issue channelsmod__channel_id() obta...
X Description: Summary This PR addresses OOM-0014 from gh-151763. It fixes a crash in _interpchannels._channel_id() when memory allocation fails while looking up module state. Issue channelsmod__channel_id() obta...
Opengraph URL: https://github.com/python/cpython/pull/151902
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:7627b0e5-b4b3-141b-d742-05478fa0abff |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 91BA:281FF8:B6208E:F51B8C:6A529BCB |
| html-safe-nonce | f8af098f75618ce90ac44c1908eb52cf23f54cb303c14b24a3ecddc5e7c322e1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MUJBOjI4MUZGODpCNjIwOEU6RjUxQjhDOjZBNTI5QkNCIiwidmlzaXRvcl9pZCI6IjM2OTUxMzM5MTMyNzYxMjgyMDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 36c4a3f665ae1e9cc6e2678ee25c71dd9680a861e3e9f2e1316fe387270ecb4b |
| hovercard-subject-tag | pull_request:3909242639 |
| 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/151902/files |
| twitter:image | https://avatars.githubusercontent.com/u/165761530?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/165761530?s=400&v=4 |
| og:image:alt | Summary This PR addresses OOM-0014 from gh-151763. It fixes a crash in _interpchannels._channel_id() when memory allocation fails while looking up module state. Issue channelsmod__channel_id() obta... |
| 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