Skip to content

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

Merged
hugovk merged 1 commit into
python:3.14from
hugovk:backport-665bda9-3.14
Nov 20, 2026
Merged

hugovk merged 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>
@hugovk
hugovk merged commit fadb2db into python:3.14 Nov 20, 2026
55 checks passed
@hugovk
hugovk deleted the backport-665bda9-3.14 branch November 20, 2026 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants