Skip to content

Commit 40ae788

Browse files
committed
Fix BZ 69614 - invalid priority field values should be ignored
1 parent 744ba42 commit 40ae788

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -477,15 +477,24 @@ protected void readPriorityUpdateFrame(int payloadSize, ByteBuffer buffer) throw
477477

478478
ByteArrayInputStream bais = new ByteArrayInputStream(payload, 4, payloadSize - 4);
479479
Reader r = new BufferedReader(new InputStreamReader(bais, StandardCharsets.US_ASCII));
480-
Priority p = Priority.parsePriority(r);
481480

482-
if (log.isTraceEnabled()) {
483-
log.trace(sm.getString("http2Parser.processFramePriorityUpdate.debug", connectionId,
484-
Integer.toString(prioritizedStreamID), Integer.toString(p.getUrgency()),
485-
Boolean.valueOf(p.getIncremental())));
486-
}
481+
try {
482+
Priority p = Priority.parsePriority(r);
487483

488-
output.priorityUpdate(prioritizedStreamID, p);
484+
if (log.isTraceEnabled()) {
485+
log.trace(sm.getString("http2Parser.processFramePriorityUpdate.debug", connectionId,
486+
Integer.toString(prioritizedStreamID), Integer.toString(p.getUrgency()),
487+
Boolean.valueOf(p.getIncremental())));
488+
}
489+
490+
output.priorityUpdate(prioritizedStreamID, p);
491+
} catch (IllegalArgumentException iae) {
492+
// Priority frames with invalid priority field values should be ignored
493+
if (log.isTraceEnabled()) {
494+
log.trace(sm.getString("http2Parser.processFramePriorityUpdate.invalid", connectionId,
495+
Integer.toString(prioritizedStreamID)), iae);
496+
}
497+
}
489498
}
490499

491500

java/org/apache/coyote/http2/LocalStrings.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ http2Parser.processFrameHeaders.decodingDataLeft=Data left over after HPACK deco
7777
http2Parser.processFrameHeaders.decodingFailed=There was an error during the HPACK decoding of HTTP headers
7878
http2Parser.processFrameHeaders.payload=Connection [{0}], Stream [{1}], Processing headers payload of size [{2}]
7979
http2Parser.processFramePriorityUpdate.debug=Connection [{0}], Stream [{1}], Urgency [{2}], Incremental [{3}]
80+
http2Parser.processFramePriorityUpdate.invalid=Connection [{0}], Stream [{1}], Priority Update frame with invalid priority field value
8081
http2Parser.processFramePriorityUpdate.streamZero=Connection [{0}], Priority update frame received to prioritize stream zero
8182
http2Parser.processFramePushPromise=Connection [{0}], Stream [{1}], Push promise frames should not be sent by the client
8283
http2Parser.processFrameSettings.ackWithNonZeroPayload=Settings frame received with the ACK flag set and payload present

test/org/apache/coyote/http2/TestRfc9218.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.coyote.http2;
1818

1919
import java.io.IOException;
20+
import java.nio.charset.StandardCharsets;
2021

2122
import org.junit.Assert;
2223
import org.junit.Test;
@@ -146,6 +147,9 @@ public void testPriority() throws Exception {
146147
// 19 - 7021 body left
147148
// 21 - 6143 body left
148149

150+
// BZ 69614 - invalid priority update frames should be ignored
151+
sendInvalidPriorityUpdate(17);
152+
149153
// Re-order the priorities
150154
sendPriorityUpdate(17, 2, true);
151155

@@ -191,4 +195,25 @@ public void testPriority() throws Exception {
191195
ioe.printStackTrace();
192196
}
193197
}
198+
199+
200+
private void sendInvalidPriorityUpdate(int streamId) throws IOException {
201+
byte[] payload = "u=1:i".getBytes(StandardCharsets.US_ASCII);
202+
203+
byte[] priorityUpdateFrame = new byte[13 + payload.length];
204+
205+
// length
206+
ByteUtil.setThreeBytes(priorityUpdateFrame, 0, 4 + payload.length);
207+
// type
208+
priorityUpdateFrame[3] = FrameType.PRIORITY_UPDATE.getIdByte();
209+
// Stream ID
210+
ByteUtil.set31Bits(priorityUpdateFrame, 5, 0);
211+
212+
// Payload
213+
ByteUtil.set31Bits(priorityUpdateFrame, 9, streamId);
214+
System.arraycopy(payload, 0, priorityUpdateFrame, 13, payload.length);
215+
216+
os.write(priorityUpdateFrame);
217+
os.flush();
218+
}
194219
}

webapps/docs/changelog.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@
130130
<bug>69607</bug>: Allow failed initialization of MD5. Based on code
131131
submitted by Shivam Verma. (remm)
132132
</fix>
133+
<fix>
134+
<bug>69614</bug>: HTTP/2 priority frames with an invalid priority field
135+
value should be ignored. (markt)
136+
</fix>
133137
</changelog>
134138
</subsection>
135139
</section>

0 commit comments

Comments
 (0)