-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed
Labels
3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Description
Crash report
What happened?
The following code has checks to make sure the return value is a tuple and of size 2, but only in asserts which means that these checks wont happen on a non-debug build.
Lines 2093 to 2101 in b92f101
PyObject *pair = PyObject_CallMethod(exc_value, "split", "(O)", | |
match_type); | |
if (pair == NULL) { | |
return -1; | |
} | |
assert(PyTuple_CheckExact(pair)); | |
assert(PyTuple_GET_SIZE(pair) == 2); | |
*match = Py_NewRef(PyTuple_GET_ITEM(pair, 0)); | |
*rest = Py_NewRef(PyTuple_GET_ITEM(pair, 1)); |
So you can create an ExceptionGroup subclass with a custom split
function that doesnt return a tuple, and it will try to interpret that object as a tuple.
PoC
class Evil(BaseExceptionGroup):
def split(self, *args):
return "NOT A TUPLE!"
print("Running...")
try:
raise Evil("wow!", [Exception()])
except* Exception:
pass
print("program should crash before reaching this")
Output
Running...
Segmentation fault (core dumped)
CPython versions tested on:
3.11, 3.12, 3.13
Operating systems tested on:
Linux, Windows
Output from running 'python -VV' on the command line:
No response
Linked PRs
- gh-128049: Fix type confusion bug with the return value of a custom ExceptionGroup split function #128079
- [3.13] gh-128049: Fix type confusion bug with the return value of a custom ExceptionGroup split function (GH-128079) #128139
- [3.12] gh-128049: Fix type confusion bug with the return value of a custom ExceptionGroup split function (GH-128079) #128140
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump