Skip to content

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

Merged
cmaloney merged 1 commit into
python:mainfrom
yangbaechu:pyio-readinto-partial-buffer
Nov 23, 2026
Merged

cmaloney merged 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.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Nov 17, 2026
@cmaloney
cmaloney merged commit 22691a3 into python:main Nov 23, 2026
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants