Skip to content

Commit

Permalink
http2: receiving too much data is a protocol error
Browse files Browse the repository at this point in the history
Updates golang/go#25023

Change-Id: Icd37dfef1b9558b0e774f1637c5566fb444666d5
Reviewed-on: https://go-review.googlesource.com/111679
Reviewed-by: Brad Fitzpatrick <[email protected]>
Run-TryBot: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
  • Loading branch information
fraenkel authored and bradfitz committed May 22, 2018
1 parent 8e0cdda commit 9ef9f5b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion http2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,10 @@ func (sc *serverConn) processData(f *DataFrame) error {
// Sender sending more than they'd declared?
if st.declBodyBytes != -1 && st.bodyBytes+int64(len(data)) > st.declBodyBytes {
st.body.CloseWithError(fmt.Errorf("sender tried to send more than declared Content-Length of %d bytes", st.declBodyBytes))
return streamError(id, ErrCodeStreamClosed)
// RFC 7540, sec 8.1.2.6: A request or response is also malformed if the
// value of a content-length header field does not equal the sum of the
// DATA frame payload lengths that form the body.
return streamError(id, ErrCodeProtocol)
}
if f.Length > 0 {
// Check whether the client has flow control quota.
Expand Down
19 changes: 19 additions & 0 deletions http2/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3764,3 +3764,22 @@ func TestIssue20704Race(t *testing.T) {
resp.Body.Close()
}
}

func TestServer_Rejects_TooSmall(t *testing.T) {
testServerResponse(t, func(w http.ResponseWriter, r *http.Request) error {
return nil
}, func(st *serverTester) {
st.writeHeaders(HeadersFrameParam{
StreamID: 1, // clients send odd numbers
BlockFragment: st.encodeHeader(
":method", "POST",
"content-length", "4",
),
EndStream: false, // to say DATA frames are coming
EndHeaders: true,
})
st.writeData(1, true, []byte("12345"))

st.wantRSTStream(1, ErrCodeProtocol)
})
}

0 comments on commit 9ef9f5b

Please sign in to comment.