Skip to content

gh-163129: Size new generators from the frame's code object - #163130

Open
alexmalyshev wants to merge 1 commit into
python:mainfrom
alexmalyshev:fix-make-coro-frame-code
Open

alexmalyshev wants to merge 1 commit into
python:mainfrom
alexmalyshev:fix-make-coro-frame-code

Conversation

@alexmalyshev

@alexmalyshev alexmalyshev commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Currently RETURN_GENERATOR sizes the new generator (and determines its type) from the code object loaded from the function on the current frame. This is not necessarily the same code object that was current when the frame was actually pushed. The function's code could have been re-assigned in the interim. This is dangerous as the generator's frame size won't match that of the interpreter, and when the interpreter goes to call _PyFrame_Copy it risks a heap overflow.

Pass the frame's code object to _Py_MakeCoro() instead.

Currently RETURN_GENERATOR sizes the new generator (and determines its
type) from the code object loaded from the function on the current
frame.  This is not necessarily the same code object that was current
when the frame was actually pushed.  The function's __code__ could have
been re-assigned in the interim.  This is dangerous as the generator's
frame size won't match that of the interpreter, and when the interpreter
goes to call _PyFrame_Copy it risks a heap overflow.

Pass the frame's code object to _Py_MakeCoro() explicitly instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant