Skip to content

gh-159739: Respect readline limits after a short read - #159974

Open
jelle-openai wants to merge 1 commit into
python:mainfrom
jelle-openai:jelle/codex/gh-159739-readline-limit
Open

jelle-openai wants to merge 1 commit into
python:mainfrom
jelle-openai:jelle/codex/gh-159739-readline-limit

Conversation

@jelle-openai

@jelle-openai jelle-openai commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

When a binary IOBase subclass provides peek() and read() returns fewer bytes than requested, readline(size) calculates subsequent reads against the original limit instead of the number of bytes still allowed. It can consume and return more than size bytes, leaving less data for the next read. Apply the remaining limit in both the C and pure-Python implementations.

Backport to 3.15 and 3.14. Both branches use a bytearray instead of PyBytesWriter; the test lives in Lib/test/test_io.py on 3.14.

Backport to 3.15 and 3.14. Both branches use a bytearray instead of PyBytesWriter; the test lives in Lib/test/test_io.py on 3.14.
@JelleZijlstra JelleZijlstra added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants