Skip to content

Commit

Permalink
http2: accept zero-length block fragments in HEADERS frames
Browse files Browse the repository at this point in the history
Fix a fencepost error which rejects HEADERS frames with neither
payload nor padding, but accepts ones with padding and no payload.

Fixes golang/go#47851.

Change-Id: Ic6ed65571366e86980a5ec69e7f9e6ab958f3b07
Reviewed-on: https://go-review.googlesource.com/c/net/+/344029
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
  • Loading branch information
neild committed Sep 2, 2021
1 parent 79fd2fe commit ce12aeb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ func parseHeadersFrame(_ *frameCache, fh FrameHeader, p []byte) (_ Frame, err er
return nil, err
}
}
if len(p)-int(padLength) <= 0 {
if len(p)-int(padLength) < 0 {
return nil, streamError(fh.StreamID, ErrCodeProtocol)
}
hf.headerFragBuf = p[:len(p)-int(padLength)]
Expand Down
17 changes: 17 additions & 0 deletions frame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,23 @@ func TestWriteHeaders(t *testing.T) {
headerFragBuf: []byte("abc"),
},
},
{
"zero length",
HeadersFrameParam{
StreamID: 42,
Priority: PriorityParam{},
},
"\x00\x00\x00\x01\x00\x00\x00\x00*",
&HeadersFrame{
FrameHeader: FrameHeader{
valid: true,
StreamID: 42,
Type: FrameHeaders,
Length: 0,
},
Priority: PriorityParam{},
},
},
}
for _, tt := range tests {
fr, buf := testFramer()
Expand Down

0 comments on commit ce12aeb

Please sign in to comment.