Skip to content

gh-155074: Fix remaining-space calculation in _pyio.BufferedReader.readinto() - #155075

Open
yangbaechu wants to merge 1 commit into
python:mainfrom
yangbaechu:pyio-readinto-partial-buffer
Open

gh-155074: Fix remaining-space calculation in _pyio.BufferedReader.readinto()#155075
yangbaechu wants to merge 1 commit into
python:mainfrom
yangbaechu:pyio-readinto-partial-buffer

Conversation

@yangbaechu

@yangbaechu yangbaechu commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Closes #155074.

This PR fixes _pyio.BufferedReader.readinto() when data from the internal buffer only partially fills the destination before a refill.

The pure Python implementation limited each buffered copy by the destination's original length. After earlier bytes had been copied, this could make the next copy exceed the remaining memoryview slice and raise ValueError. The copy is now limited by the remaining destination space, len(buf) - written.

The regression test is shared by the C and pure Python implementations and verifies the returned byte count, destination contents, and unread data.

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.

_pyio.BufferedReader.readinto() can raise ValueError after partially filling the destination

1 participant