Skip to content

[3.14] gh-159739: Keep text I/O state valid across reentrant callbacks (GH-160398) - #162096

Open
hugovk wants to merge 1 commit into
python:3.14from
hugovk:backport-665bda9-3.14
Open

hugovk wants to merge 1 commit into
python:3.14from
hugovk:backport-665bda9-3.14

Conversation

@hugovk

@hugovk hugovk commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

A raw read can reinitialize a TextIOWrapper as write-only, and codec callbacks or finalizers can release an encoder, decoder, or decoded chunk while a read or write still needs it. This can crash the interpreter. Check that a decoder is still available after reading, keep codecs alive across calls, and read the chunk length before transferring ownership. Also recheck StringIO after converting the truncate size because index() can close the stream. (cherry picked from commit 665bda9)

…llbacks (pythonGH-160398)

A raw read can reinitialize a TextIOWrapper as write-only, and codec callbacks or finalizers can release an encoder, decoder, or decoded chunk while a read or write still needs it. This can crash the interpreter. Check that a decoder is still available after reading, keep codecs alive across calls, and read the chunk length before transferring ownership. Also recheck StringIO after converting the truncate size because __index__() can close the stream.
(cherry picked from commit 665bda9)

Co-authored-by: Jelle Zijlstra <jelle@openai.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.

2 participants