Skip to content

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

Merged
JelleZijlstra merged 2 commits into
python:3.15from
miss-islington:backport-665bda9-3.15
Nov 2, 2026
Merged

JelleZijlstra merged 2 commits 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>
@picnixz

picnixz commented Nov 1, 2026

Copy link
Copy Markdown
Member

@JelleZijlstra you have some conflicts here

@JelleZijlstra
JelleZijlstra enabled auto-merge (squash) November 2, 2026 00:54
@JelleZijlstra

Copy link
Copy Markdown
Member

Thanks, was just another test added in the same place

@JelleZijlstra
JelleZijlstra merged commit 0262ca1 into python:3.15 Nov 2, 2026
54 checks passed
@miss-islington
miss-islington deleted the backport-665bda9-3.15 branch November 2, 2026 01:27
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.

4 participants