protocol: safely resize header buffer based on length field#150
Closed
protocol: safely resize header buffer based on length field#150
Conversation
5a48d71 to
a8ba414
Compare
dd43193 to
6e1f8eb
Compare
This was referenced Feb 4, 2026
emersion
reviewed
Feb 5, 2026
| // If the header is larger than our current buffer, wrap the existing | ||
| // reader in a larger one. This preserves any bytes already buffered. | ||
| if totalSize > p.bufReader.Size() { | ||
| p.bufReader = bufio.NewReaderSize(p.bufReader, totalSize) |
Contributor
There was a problem hiding this comment.
Manually resizing the buffer seems more complicated than necessary: I don't think we need to do that. See #155 for a simpler version.
This also results in paying the memory cost for the TLVs twice: once for the internal bufio.Reader buffer, and another time when reading TLVs as a byte slice.
Contributor
There was a problem hiding this comment.
More generally, bufio.Reader's internal buffer size is not supposed to be client-controlled. It's supposed to act as a way to avoid large allocations.
emersion
reviewed
Feb 5, 2026
| if totalSize, ok := v2PreflightHeaderSize(peeked); ok { | ||
| // If the header is larger than our current buffer, wrap the existing | ||
| // reader in a larger one. This preserves any bytes already buffered. | ||
| if totalSize > p.bufReader.Size() { |
Contributor
There was a problem hiding this comment.
This can result in a DoS if the client sends 65535 as the length.
Owner
Author
|
Closing in favor of #155. |
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.
Fixes #123
Refs #144
WDYT @emersion @bollenberger?