Skip to content

Commit

Permalink
[internal-branch.go1.17-vendor] http2: accept zero-length block fragm…
Browse files Browse the repository at this point in the history
…ents in HEADERS frames

Fix a fencepost error which rejects HEADERS frames with neither
payload nor padding, but accepts ones with padding and no payload.

Updates golang/go#49077

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>
Reviewed-on: https://go-review.googlesource.com/c/net/+/357672
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
  • Loading branch information
neild authored and dmitshur committed Oct 29, 2021
1 parent 553fb77 commit c302542
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 c302542

Please sign in to comment.