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
PyEval_GetFrame crashes when it returns incomplete frames #96975
Is it possible that PyEval_GetFrame returns 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 calling PyEval_GetFrame from there. As the allocator can be called at random points of the eval loop (for example here) is perfectly possible that a legitimate call to PyEval_GetFrame returns an incomplete frame.
changed the title [-]`PyEval_GetFrame` crashes if it returns incomplete frames[/-][+]`PyEval_GetFrame` crashes when it returns incomplete frames[/+]on Sep 20, 2022
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 sys._getframe(). The logic for skipping incomplete frames doesn't seem to happen anymore once you've walked back to the desired depth.
I wonder if we should expose the _PyFrame_IsIncomplete function so if there are more cases like this extension authors can protect their code against this meanwhile we release a fix. Thoughts?
Activity
pablogsal commentedon Sep 20, 2022
CC: @markshannon @brandtbucher @ericsnowcurrently @iritkatriel
brandtbucher commentedon Sep 20, 2022
Typo? Are you asking us if it's possible, or telling us it is?
pablogsal commentedon Sep 20, 2022
I am telling you
[-]`PyEval_GetFrame` crashes if it returns incomplete frames[/-][+]`PyEval_GetFrame` crashes when it returns incomplete frames[/+]pablogsal commentedon Sep 20, 2022
It may be easier to reproduce by using generators.
brandtbucher commentedon Sep 20, 2022
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.
brandtbucher commentedon Sep 20, 2022
It may also be possible in
sys._getframe(). The logic for skipping incomplete frames doesn't seem to happen anymore once you've walked back to the desired depth.brandtbucher commentedon Sep 20, 2022
Ah wait, I think
sys._getframe()is okay actually. I don't think it can be called from an incomplete frame.10 remaining items
kumaraditya303 commentedon Sep 21, 2022
That indeed fixes the issue and avoids code duplication.
pythonGH-96975: Skip incomplete frames in PyEval_GetFrame (pythonGH-9…
GH-96975: Skip incomplete frames in PyEval_GetFrame (GH-97003)
GH-96975: Skip incomplete frames in PyEval_GetFrame (GH-97018)
brandtbucher commentedon Sep 22, 2022
Actually, I'll let Pablo close this once it's cherry picked to the stable release.
pablogsal commentedon Sep 28, 2022
I wonder if we should expose the
_PyFrame_IsIncompletefunction so if there are more cases like this extension authors can protect their code against this meanwhile we release a fix. Thoughts?GH-96975: Skip incomplete frames in PyEval_GetFrame (GH-97018)
Fidget-Spinner commentedon Oct 26, 2022
I'm closing this and removing release blocker label as I've seen it cherry picked on the official announcement https://mail.python.org/archives/list/python-dev@python.org/thread/SB5PWB32JQHE7QFIULXIZIGUFPKSYEKP/.