gh-151763: Fix OOM-0014 crash in _interpchannels._channel_id#151902
Open
zainnadeem786 wants to merge 1 commit into
Open
gh-151763: Fix OOM-0014 crash in _interpchannels._channel_id#151902zainnadeem786 wants to merge 1 commit into
zainnadeem786 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:get_module_from_owned_type()eventually calls_get_current_module(), which allocates the module name using:Under out-of-memory conditions this allocation can fail and return
NULLwith a pendingMemoryError.Before this change,
channelsmod__channel_id()assumed the helper could never fail.As a result:
because
mod == NULL.which dereferences
NULLand 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 returnNULLwhen_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:
This preserves the existing invariant check while correctly propagating the pending
MemoryErrorinstead of aborting or crashing.Validation
I reproduced the issue locally on both debug and release builds.
Before the fix
Debug build:
Release build:
After the fix
The same OOM path now returns a clean
MemoryErrorand no longer aborts or crashes.Regression Test
Added a focused subprocess regression test in:
The test:
_testcapi.set_nomemory(0, 1)_interpchannels._channel_id(0)MemoryErroris propagated instead of aborting or crashingThe test is skipped under
Py_TRACE_REFS, matching the existing limitations of_testcapi.set_nomemory().Tests
Executed:
Result:
I also verified:
which reports no patch formatting issues (only existing LF/CRLF working-copy warnings).
NEWS
Added a NEWS fragment describing the crash fix and
MemoryErrorpropagation.Addresses OOM-0014 from gh-151763.