do not let Body read beyond its length#282
Merged
jbr merged 1 commit intohttp-rs:mainfrom Nov 23, 2020
Merged
Conversation
7907ebe to
892daba
Compare
892daba to
91e19bc
Compare
jbr
commented
Nov 15, 2020
| Pin::new(&mut self.reader).poll_read(cx, buf) | ||
| let mut buf = match self.length { | ||
| None => buf, | ||
| Some(length) if length == self.bytes_read => return Poll::Ready(Ok(0)), |
Member
Author
There was a problem hiding this comment.
this line is an optional optimization and could be removed if it makes the code more readable to do so. i was on the fence about this tradeoff
Fishrock123
reviewed
Nov 16, 2020
| Some(length) if length == self.bytes_read => return Poll::Ready(Ok(0)), | ||
| Some(length) => { | ||
| let max_len = (length - self.bytes_read).min(buf.len()); | ||
| &mut buf[0..max_len] |
Member
There was a problem hiding this comment.
Will this panic if the body has more bytes than it specifies?
Member
Author
There was a problem hiding this comment.
nope, there's a test for that. we just won't read them from the underlying Read, which is the correct behavior for keepalive
Member
Author
There was a problem hiding this comment.
this line limits the length of the mutable slice that we pass into the inner read implementation, effectively telling it "give me a maximum of max_len bytes"
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.
this logic is currently handled in several places in async-h1, but it should be the responsibility of Body to ensure that if it has a set length, it will not read beyond that length.
I believe this is semver-patch, unless we consider "reading past set body length" intended behavior