Skip to content

Commit

Permalink
http2: receiving too much data is a protocol error (#713)
Browse files Browse the repository at this point in the history
  • Loading branch information
YuqiXiao authored Mar 5, 2021
1 parent 4240449 commit c4f3a62
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bfe_http2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,10 @@ func (sc *serverConn) processData(f *DataFrame) error {
if st.declBodyBytes != -1 && st.bodyBytes+int64(len(data)) > st.declBodyBytes {
err := fmt.Errorf("sender tried to send more than declared Content-Length of %d bytes", st.declBodyBytes)
st.body.CloseWithError(err)
return StreamError{id, ErrCodeStreamClosed, err.Error()}
// 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, err.Error()}
}
if f.Length > 0 {
// Check whether the client has flow control quota.
Expand Down
19 changes: 19 additions & 0 deletions bfe_http2/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3005,3 +3005,22 @@ func TestNoRstPostAfterGOAWAY(t *testing.T) {
}

}

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 c4f3a62

Please sign in to comment.