Skip to content

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

Open
miss-islington wants to merge 1 commit into
python:3.15from
miss-islington:backport-665bda9-3.15
Open

miss-islington wants to merge 1 commit into
python:3.15from
miss-islington:backport-665bda9-3.15

Conversation

@miss-islington

@miss-islington miss-islington commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

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

…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