[New-bugs-announce] [issue45786] Avoid allocating when exiting frame; it may be unsafe.
Mark Shannon
report at bugs.python.org
Thu Nov 11 10:04:09 EST 2021
New submission from Mark Shannon <mark at hotpy.org>:
We exiting a frame (returning from a Python function) we have to release the stack allocated frame. If a heap-allocated frame object exists, we need to copy the contents of the (stack) frame into the frame object.
However, this involves allocating memory for the copy. Allocating memory can invoke GC, causing arbitrary code to be run, or the allocation can fail. Either leaves us in a precarious state, which may be unsafe.
I haven't been able to produce a crash, but I'm not sure that there isn't a potential crash lurking there either.
The fix is fairly simple. Allocate space for the copy of the frame at the end of the frame object. Then we need to copy the data, space will have already been allocated, and nothing can fail.
Since, in theory, heap-allocated frames are relatively rare, the extra memory used won't be an issue.
----------
assignee: Mark.Shannon
components: Interpreter Core
keywords: 3.11regression
messages: 406163
nosy: Mark.Shannon, pablogsal
priority: normal
severity: normal
status: open
title: Avoid allocating when exiting frame; it may be unsafe.
type: crash
versions: Python 3.11
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45786>
_______________________________________
More information about the New-bugs-announce
mailing list