Skip to content

Commit 14c0235

Browse files
neilddmitshur
authored andcommitted
[internal-branch.go1.17-vendor] http2: accept zero-length block fragments 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 <[email protected]> Run-TryBot: Damien Neil <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Reviewed-on: https://go-review.googlesource.com/c/net/+/357672 Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 0d2c43c commit 14c0235

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

http2/frame.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ func parseHeadersFrame(_ *frameCache, fh FrameHeader, p []byte) (_ Frame, err er
10181018
return nil, err
10191019
}
10201020
}
1021-
if len(p)-int(padLength) <= 0 {
1021+
if len(p)-int(padLength) < 0 {
10221022
return nil, streamError(fh.StreamID, ErrCodeProtocol)
10231023
}
10241024
hf.headerFragBuf = p[:len(p)-int(padLength)]

http2/frame_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,23 @@ func TestWriteHeaders(t *testing.T) {
312312
headerFragBuf: []byte("abc"),
313313
},
314314
},
315+
{
316+
"zero length",
317+
HeadersFrameParam{
318+
StreamID: 42,
319+
Priority: PriorityParam{},
320+
},
321+
"\x00\x00\x00\x01\x00\x00\x00\x00*",
322+
&HeadersFrame{
323+
FrameHeader: FrameHeader{
324+
valid: true,
325+
StreamID: 42,
326+
Type: FrameHeaders,
327+
Length: 0,
328+
},
329+
Priority: PriorityParam{},
330+
},
331+
},
315332
}
316333
for _, tt := range tests {
317334
fr, buf := testFramer()

0 commit comments

Comments
 (0)