New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PyEval_GetFrame crashes when it returns incomplete frames
#96975
Comments
|
Typo? Are you asking us if it's possible, or telling us it is? |
|
I am telling you |
PyEval_GetFrame crashes if it returns incomplete framesPyEval_GetFrame crashes when it returns incomplete frames
|
It may be easier to reproduce by using generators. |
|
It seems to me that the correct thing to do in this case is to walk back over the frames until we reach a "complete" one, like we do in other places. Not 100% sure yet. |
|
It may also be possible in |
|
Ah wait, I think |
|
It is possible to trigger this assertion using the C API. In
|
|
Thanks. I'll have to pick this back up tomorrow morning (might find some time tonight). |
Thanks for the reproducer, which concisely demonstrates the bug. That's super helpful. There's a possible caveat, but only relating to the ways (and likelihood) the bug could be triggered in the wild. FWIW, my understanding is that the CPython runtime expects the allocator to stay the same from initialization to finalization, so @vstinner would probably know for sure. UPDATE: There is no caveat. Extensions can use |
|
Looking at the code, shouldn't we just call |
|
FYI, this was fixed for signal handlers a week ago in #96776. The assertion was added by Mark in July in #94371. All the other places that call |
|
Python/initconfig.c calls The Python memory allocator must be configured by the Python pre-initialization, or just after the pre-initialization, and before the Python initialization.
Setting a hook on existing allocators, like what tracemalloc does, is different and safe while Python is running. |
sorry, short reply: yes :-) |
I didn't look very closely at |
The reproducer from #96975 (comment) does exactly that (simply wrapping the already-set allocator) so it's a legitimate example. |
They look safe, since tracing doesn't happen if we're in an incomplete state. The definition of |
That indeed fixes the issue and avoids code duplication. |
pablogsal commentedSep 20, 2022
•
edited
Is it possible that
PyEval_GetFramereturns incomplete frames. When this happens, Python segfaults in release mode or crashes in debug mode because of the check for incomplete frames in_PyFrame_GetFrameObject. This is reproducible in many ways involving C extensions, the easier one may be by installing a custom memory allocator for all the domains and callingPyEval_GetFramefrom there. As the allocator can be called at random points of the eval loop (for example here) is perfectly possible that a legitimate call toPyEval_GetFramereturns an incomplete frame.The text was updated successfully, but these errors were encountered: