New submission from Mark Shannon <m...@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 <rep...@bugs.python.org> <https://bugs.python.org/issue45786> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com