gh-151763: Fix debug assertion in unicode subtype cleanup under OOM#152164
Open
zainnadeem786 wants to merge 1 commit into
Open
gh-151763: Fix debug assertion in unicode subtype cleanup under OOM#152164zainnadeem786 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-0030 from gh-151763.
It fixes a debug-build assertion that can occur while cleaning up a partially constructed Unicode subtype after an allocation failure.
Issue
unicode_subtype_new()allocates a non-compact Unicode subtype object and initializes its internal state before allocating the backing character buffer.If allocating that buffer fails, the constructor cleans up using:
At that point the object is valid enough to own a reference, but its internal data pointer is still
NULL.During debug builds, deallocation calls
unicode_is_singleton(). For length-1 strings that helper reads the first character using:For a partially initialized non-compact Unicode object this reaches the internal assertion:
causing the interpreter to abort instead of propagating the pending
MemoryError.Fix
Before reading the first character,
unicode_is_singleton()now detects the temporary construction state:A non-compact Unicode object with a
NULLdata pointer cannot represent a singleton, so returning0is correct while avoiding the invalid debug-only access.The constructor, ownership model, and cleanup logic remain unchanged.
Validation
Built locally:
Reproduced the original OOM path using
_testcapi.set_nomemory().Before
The reproducer aborted with:
After
The same allocation-failure sweep completes without triggering the assertion and correctly propagates
MemoryError.Tests
Executed focused Unicode test suites:
All passed.
I also verified:
No whitespace issues were reported.
Notes
No regression test is included.
The reproducer relies on
_testcapi.set_nomemory()and allocation-failure indices that are build-sensitive, making it difficult to provide a stable CI regression test for this specific OOM path.Addresses OOM-0030 from gh-151763.