Skip to content

Commit dc080cd

Browse files
committed
Fix bug in HTTP/2 headers parsing
1 parent 9cc710f commit dc080cd

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@
105105
issues do not "pop up" wrt. others).
106106
-->
107107
<section name="Tomcat 11.0.21 (markt)" rtext="in development">
108+
<subsection name="Coyote">
109+
<changelog>
110+
<fix>
111+
Fix an HTTP/2 header frame parsing bug that could result in a connection
112+
being closed without a <code>GOAWAY</code> frame if an invalid
113+
<code>HEADERS</code> frame was received. (markt)
114+
</fix>
115+
</changelog>
116+
</subsection>
108117
</section>
109118
<section name="Tomcat 11.0.20 (markt)" rtext="release in progress">
110119
<subsection name="Coyote">

0 commit comments

Comments
 (0)