cpython/Modules/_io
Miss Islington (bot) a5eaa14584
[3.11] gh-95782: Fix io.BufferedReader.tell() etc. being able to return offsets < 0 (GH-99709) (GH-115600)
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:55:43 +02:00
..
clinic [3.11] gh-107801: Document io.TextIOWrapper.tell (#108265) (#108548) 2023-08-27 21:22:43 +00:00
_iomodule.c [3.11] Trim trailing whitespace and test on CI (GH-104275) (#108215) 2023-08-22 12:57:31 +03:00
_iomodule.h bpo-46765: Replace Locally Cached Strings with Statically Initialized Objects (gh-31366) 2022-02-22 17:23:51 -07:00
bufferedio.c [3.11] gh-95782: Fix io.BufferedReader.tell() etc. being able to return offsets < 0 (GH-99709) (GH-115600) 2024-02-17 14:55:43 +02:00
bytesio.c [3.11] gh-111174: Fix crash in getbuffer() called repeatedly for empty BytesIO (GH-111210) (GH-111315) 2023-10-25 11:18:30 +00:00
fileio.c [3.11] gh-107913: Fix possible losses of OSError error codes (GH-107930) (GH-108524) 2023-08-27 12:18:58 +00:00
iobase.c [3.11] gh-107801: Improve the accuracy of io.IOBase.seek docs (#108268) (#108656) 2023-08-29 19:57:49 +00:00
stringio.c bpo-46765: Replace Locally Cached Strings with Statically Initialized Objects (gh-31366) 2022-02-22 17:23:51 -07:00
textio.c [3.11] gh-80109: Fix io.TextIOWrapper dropping the internal buffer during write() (GH-22535) (GH-113809) 2024-01-08 10:47:50 +00:00
winconsoleio.c gh-110913: Fix WindowsConsoleIO chunking of UTF-8 text (GH-111007) 2023-10-20 12:19:04 +00:00