You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Creating an ExceptionGroup segfaults on MemoryError in debug builds #159294
BaseExceptionGroup_new() in Objects/exceptions.c passes the result of BaseException_new() straight to PyBaseExceptionGroupObject_CAST():
PyBaseExceptionGroupObject*self=PyBaseExceptionGroupObject_CAST(BaseException_new(cls, args, kwds));
if (!self) {
goto error;
}
The cast asserts _PyBaseExceptionGroup_Check(exc), which dereferences its argument, so when BaseException_new() fails with MemoryError a debug build segfaults before reaching the NULL check.
On main (627eabf) built with --with-pydebug, this segfaults:
#0 PyObject_TypeCheck (ob=ob@entry=0x0, type=0x555555b82380 <_PyExc_BaseExceptionGroup>) at ./Include/object.h:375
#1 0x00005555556a35c0 in PyBaseExceptionGroupObject_CAST (exc=0x0) at Objects/exceptions.c:861
#2 0x00005555556a59e3 in BaseExceptionGroup_new (type=<optimized out>, args=0x7ffff736d910, kwds=0x0) at Objects/exceptions.c:977
Release builds raise MemoryError as expected. The cast came with gh-111178, and the same code is in 3.14 and 3.15.
Checking the result of BaseException_new() before casting it fixes the crash.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Activity
srinivasreddy commentedon Oct 13, 2026
I can confirm the bug on windows too.
gh-159294: Fix crash when creating an `ExceptionGroup` fails with `Me…
[3.15] gh-159294: Fix crash when creating an `ExceptionGroup` fails w…