]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-143008: Fix Null pointer dereferences in TextIOWrapper underlying stream access...
authorCody Maloney <cmaloney@users.noreply.github.com>
Tue, 9 Jun 2026 10:31:44 +0000 (03:31 -0700)
committerGitHub <noreply@github.com>
Tue, 9 Jun 2026 10:31:44 +0000 (12:31 +0200)
commitdb4b1948bc4ad5e7230fe1f2814da409ca1d669b
tree9425e003d1128683077e529e23f704095b39d716
parent3186547c1ec76e1afab82ec32271ec5b9467fdeb
gh-143008: Fix Null pointer dereferences in TextIOWrapper underlying stream access (#145957)

TextIOWrapper keeps its underlying stream in a member called
`self->buffer`. That stream can be detached by user code, such as custom
`.flush` implementations resulting in `self->buffer` being set to NULL.
The implementation often checked at the start of functions if
`self->buffer` is in a good state, but did not always recheck after
other Python code was called which could modify `self->buffer`.

The cases which need to be re-checked are hard to spot so rather than
rely on reviewer effort create better safety by making all self->buffer
access go through helper functions.

Thank you yihong0618 for the test, NEWS and initial implementation in
gh-143041.

Co-authored-by: yihong0618 <zouzou0208@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Lib/test/test_io/test_textio.py
Misc/NEWS.d/next/Library/2025-12-21-17-56-37.gh-issue-143008.aakErJ.rst [new file with mode: 0644]
Misc/NEWS.d/next/Library/2026-06-04-18-22-56.gh-issue-143008.z5tw-J.rst [new file with mode: 0644]
Modules/_io/clinic/textio.c.h
Modules/_io/textio.c