Repository navigation
gh-159294: Fix crash when creating an ExceptionGroup fails with MemoryError - #159295
Merged
StanFromIreland merged 2 commits intoOct 23, 2026
Merged
StanFromIreland merged 2 commits into
StanFromIreland merged 2 commits into
Conversation
… MemoryError BaseExceptionGroup_new() passed the result of BaseException_new() to PyBaseExceptionGroupObject_CAST() before checking it for NULL. The cast asserts the type of its argument, so a debug build dereferenced NULL instead of raising MemoryError.
StanFromIreland
approved these changes
Oct 14, 2026
Contributor
Author
|
Hi @iritkatriel, just checking in on this PR. With approvals and green CI, is there anything else needed before merging? The fix should backport cleanly to 3.14 and 3.15, only the regression test needs adapting since Thanks! |
StanFromIreland
enabled auto-merge (squash)
October 23, 2026 19:32
Member
|
I fixed a little nit and enabled auto-merge. |
|
Thanks @christianaurichzm for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15. |
|
GH-160504 is a backport of this pull request to the 3.15 branch. |
|
GH-160505 is a backport of this pull request to the 3.14 branch. |
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.
Fixes #159294
BaseExceptionGroup_new()passed the result ofBaseException_new()toPyBaseExceptionGroupObject_CAST()before checking it forNULL. The cast asserts_PyBaseExceptionGroup_Check()on its argument, so when the allocation fails a debug build dereferencesNULLinstead of raisingMemoryError. Release builds are unchanged, since they already returnedNULLwithMemoryErrorset.This change checks the result before the cast.
Verification
test_exception_groupsegfaults an unpatched debug build and passes with the fix, also with-R 3:3.test_exception_group,test_exceptions,test_except_starandtest_tracebackpass on a debug build.The test uses
_testcapi.call_with_nomemory(), which only exists on main, so the 3.15 and 3.14 backports will need to adapt it.