Skip to content

gh-160811: fix TextIOWrapper.tell() after seek() past a carriage return - #160812

Open
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:textio-tell-seek-cr
Open

tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:textio-tell-seek-cr

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

seek() to a cookie with chars_to_skip > 0 replays the input chunk into a new snapshot but kept the bytes-per-char ratio from the previous _read_chunk(), so tell() could compute a skip larger than the snapshot. the C implementation then read past the bytes object, and _pyio returned a position one character too far. this sets the ratio from the replayed chunk in both implementations, the same way _read_chunk() does, and adds a regression test for the C and pure-Python classes. backports to 3.14 and 3.13 need the test moved to Lib/test/test_io.py.

…e return

seek() to a cookie with chars_to_skip replayed the input chunk without updating the bytes-per-char ratio, so tell() could compute skip_bytes larger than the snapshot buffer.  In the C implementation this read past the end of the buffer, and _pyio returned a wrong position.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant