GeezerVison is showing github.com — `PyEval_GetFrame` crashes when it returns incomplete frames · Issue #96975 · python/cpython
PyEval_GetFrame crashes when it returns incomplete frames #96975
DescriptionIs 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. Activitypablogsal commented on Sep 20, 2022 brandtbucher commented on Sep 20, 2022 Typo? Are you asking us if it's possible, or telling us it is? pablogsal commented on Sep 20, 2022 changed the title [-]`PyEval_GetFrame` crashes if it returns incomplete frames[/-] [+]`PyEval_GetFrame` crashes when it returns incomplete frames[/+] on Sep 20, 2022pablogsal commented on Sep 20, 2022 It may be easier to reproduce by using generators. brandtbucher commented 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. brandtbucher commented on 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 commented on Sep 20, 2022 Ah wait, I think sys._getframe() is okay actually. I don't think it can be called from an incomplete frame. kumaraditya303 commented on Sep 21, 2022
Looking at the code, shouldn't we just call PyThreadState_GetFrame() in PyEval_GetFrame()?
That indeed fixes the issue and avoids code duplication. brandtbucher commented on Sep 22, 2022 Actually, I'll let Pablo close this once it's cherry picked to the stable release. pablogsal commented on Sep 28, 2022 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? Fidget-Spinner commented on Oct 26, 2022
MetadataMetadataStatusShow more project fields
DevelopmentNo branches or pull requestsIssue actions
|