Fix readuntil missing a terminator that spans two reads - #66
Merged
Conversation
BufferedIO#readuntil resumed searching at the previous buffer end, so a multi-byte terminator split across two fills, such as "\r" ending one chunk and "\n" starting the next, was never matched and readuntil returned data past the terminator. Rewind the search by terminator.bytesize - 1 before refilling, floored at @rbuf_offset. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Cover a terminator split across two reads and across more than two, the negative rewind the floor clamps, the floor keeping the search out of consumed bytes, and the ignore_eof branch that returns data without a terminator. FakeReadPartialIO now signals EOF instead of raising TypeError, and hands out binary chunks so @rbuf stays binary the way a real IO leaves it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Running the tests leaves one behind, and a prior branch committed it by accident. Anchored to the root like every other entry. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
hsbt
force-pushed
the
readuntil-chunk-boundary
branch
from
August 25, 2026 09:37
14f7784 to
0dbbaea
Compare
hsbt
added a commit
that referenced
this pull request
Aug 25, 2026
The rewind added in #66 makes the search resume before the end of the previous read, and every limit test so far used a single-byte terminator where that rewind never moves. This is the combination the limit has to measure the result rather than how far the search looked back. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Net::BufferedIO#readuntilresumes searching from the previous buffer end after each refill, so a multi-byte terminator split across two reads, such as"\r"at the end of one chunk and"\n"at the start of the next, is never matched andreaduntilreturns data past the terminator. This can corrupt response parsing innet/httpand other clients when a CRLF straddles a packet boundary. Rewind the search offset byterminator.bytesize - 1before refilling. A regression test reads"abc\r"and"\ndef\r\n"from a fake IO and expects"abc\r\n".