cpython
cpython copied to clipboard
gh-143378: Fix UAF when `BytesIO` is concurrently mutated during `write` operations
PyObject_GetBuffer() can execute user code (e.g. via buffer), which may close or otherwise mutate a BytesIO object while write() or writelines() is in progress. This could invalidate the internal buffer and lead to a use-after-free.
Temporarily bump the exports counter while acquiring the input buffer to block re-entrant mutation, and add regression tests to ensure such cases raise BufferError instead of crashing.
- Issue: gh-143378