Skip to content

Commit 0de12dc

Browse files
committed
Fix bug in HTTP/2 headers parsing
1 parent 3ae9094 commit 0de12dc

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

java/org/apache/coyote/http2/Http2Parser.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ protected void readHeadersFrame(int streamId, int flags, int payloadSize, ByteBu
247247
} else {
248248
buffer.get(optional);
249249
}
250+
/*
251+
* The optional padLength byte and priority bytes (if any) don't count towards the payload size when
252+
* comparing payload size to padLength as required by RFC 9113, section 6.2.
253+
*/
254+
payloadSize -= optionalLen;
255+
250256
if (padding) {
251257
padLength = ByteUtil.getOneByte(optional, 0);
252258
if (padLength >= payloadSize) {
@@ -255,11 +261,10 @@ protected void readHeadersFrame(int streamId, int flags, int payloadSize, ByteBu
255261
Http2Error.PROTOCOL_ERROR);
256262
}
257263
}
258-
259-
// Ignore RFC 7450 priority data if present
260-
261-
payloadSize -= optionalLen;
264+
// The padding does not count towards the size of payload that is read below.
262265
payloadSize -= padLength;
266+
267+
// Any RFC 7450 priority data was read into the byte[] optional above. It is ignored.
263268
}
264269

265270
readHeaderPayload(streamId, payloadSize, buffer);

webapps/docs/changelog.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@
222222
Remove support for HTTP 0.9. (markt)
223223
</update>
224224
<!-- Entries for backport and removal before 12.0.0-M1 below this line -->
225+
<fix>
226+
Fix an HTTP/2 header frame parsing bug that could result in a connection
227+
being closed without a <code>GOAWAY</code> frame if an invalid
228+
<code>HEADERS</code> frame was received. (markt)
229+
</fix>
225230
</changelog>
226231
</subsection>
227232
<subsection name="Jasper">

0 commit comments

Comments
 (0)