cpython/Modules/_io
Miss Islington (bot) de347c0207
[3.12] gh-95782: Fix io.BufferedReader.tell() etc. being able to return offsets < 0 (GH-99709) (GH-115599)
lseek() always returns 0 for character pseudo-devices like
`/dev/urandom` (for other non-regular files, e.g. `/dev/stdin`, it
always returns -1, to which CPython reacts by raising appropriate
exceptions). They are thus technically seekable despite not having seek
semantics.

When calling read() on e.g. an instance of `io.BufferedReader` that
wraps such a file, `BufferedReader` reads ahead, filling its buffer,
creating a discrepancy between the number of bytes read and the internal
`tell()` always returning 0, which previously resulted in e.g.
`BufferedReader.tell()` or `BufferedReader.seek()` being able to return
positions < 0 even though these are supposed to be always >= 0.

Invariably keep the return value non-negative by returning
max(former_return_value, 0) instead, and add some corresponding tests.
(cherry picked from commit 26800cf25a)

Co-authored-by: 6t8k <58048945+6t8k@users.noreply.github.com>
2024-02-17 14:56:00 +02:00
..
clinic [3.12] gh-115015: Argument Clinic: fix generated code for METH_METHOD methods without params (#115016) (#115067) 2024-02-06 11:20:16 +01:00
_iomodule.c gh-101819: Isolate _io (#101948) 2023-05-15 09:26:27 +00:00
_iomodule.h gh-101819: Isolate _io (#101948) 2023-05-15 09:26:27 +00:00
bufferedio.c [3.12] gh-95782: Fix io.BufferedReader.tell() etc. being able to return offsets < 0 (GH-99709) (GH-115599) 2024-02-17 14:56:00 +02:00
bytesio.c [3.12] gh-111049: Fix crash during garbage collection of the BytesIO buffer object (GH-111221) (GH-113096) 2023-12-14 10:28:57 +00:00
fileio.c [3.12] gh-114286: Fix maybe-uninitialized warning in Modules/_io/fileio.c (GH-114287) (GH-114288) 2024-01-19 10:58:09 +00:00
iobase.c [3.12] gh-107801: Improve the accuracy of io.IOBase.seek docs (#108268) (#108655) 2023-08-29 22:19:08 +02:00
stringio.c gh-101819: Isolate _io (#101948) 2023-05-15 09:26:27 +00:00
textio.c [3.12] gh-80109: Fix io.TextIOWrapper dropping the internal buffer during write() (GH-22535) (GH-113808) 2024-01-08 11:00:30 +00:00
winconsoleio.c gh-110913: Fix WindowsConsoleIO chunking of UTF-8 text (GH-111007) 2023-10-20 12:37:31 +00:00