Add limit option to Net::BufferedIO#readuntil - #67
Merged
Conversation
readuntil buffers until the terminator arrives, so a peer that never sends one grows the read buffer without bound. The limit lets a protocol implementation cap what a single read may return, raising the new Net::ReadLimitExceeded instead of reading on. The exception derives from ProtocolError because an over-long line is the peer violating the protocol rather than an I/O failure, and because IOError would place it in the generic socket-error rescue that Net::HTTP retries on. ruby/net-http#315 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The floor's two reasons fit in one block, and the two tests that restated them are named for what they cover. 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#readuntilbuffers indefinitely until the terminator arrives, so a peer that never sends it can grow the read buffer without bound. This adds alimit:keyword that raises the newNet::ReadLimitExceededwhen the terminator is not found within the given number of bytes. Protocol implementations can use it to cap line length.The limit is the largest result
readuntilmay return, counting the terminator, and it never truncates the way the limit ofIO#getsdoes. The exception derives fromNet::ProtocolErrorrather thanIOError, because an over-long line is the peer violating the protocol and not an I/O failure, and becauseIOErrorwould put it in the generic socket-error rescue thatNet::HTTPretries on.Reported at ruby/net-http#315. net-http will call this from
Net::HTTPResponse.read_lineguarded bydefined?(Net::ReadLimitExceeded), so it depends on a net-protocol release shipping this first.