Skip to content

Conversation

squeek502
Copy link
Member

@squeek502 squeek502 commented Oct 17, 2025

If a Reader implementation implements stream by ignoring the Writer, writing directly to its internal buffer, and returning 0, then defaultDiscard would not update seek and also return 0, which is incorrect and can cause discardShort to violate the contract of VTable.discard by calling into vtable.discard with a non-empty buffer.

This commit fixes the problem by advancing seek up to the (remaining) limit after the stream call. This logic could likely be somewhat simplified in the future depending on how #25170 is resolved.

Fixes #25620, fixes #25619

If a Reader implementation implements `stream` by ignoring the Writer, writing directly to its internal buffer, and returning 0, then `defaultDiscard` would not update `seek` and also return 0, which is incorrect and can cause `discardShort` to violate the contract of `VTable.discard` by calling into `vtable.discard` with a non-empty buffer.

This commit fixes the problem by advancing seek up to the limit after the stream call. This logic could likely be somewhat simplified in the future depending on how ziglang#25170 is resolved.
@squeek502 squeek502 force-pushed the reader-default-discard-indirect branch from 7f84fdd to 5f14aca Compare October 18, 2025 02:19
@ianic
Copy link
Contributor

ianic commented Oct 20, 2025

Also fixes: #25619

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

defaultDiscard leaves buffer in bad state Io.Reader assert fails in http.Client.fetch for a specific url

2 participants