Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,15 @@ private void consumeFrame(final RawFrame frame) throws HttpException, IOExceptio
}
final int delta = payload.getInt() & 0x7fffffff;
if (delta == 0) {
throw new H2ConnectionException(H2Error.PROTOCOL_ERROR, "Invalid WINDOW_UPDATE delta");
if (streamId == 0) {
throw new H2ConnectionException(H2Error.PROTOCOL_ERROR, "Invalid WINDOW_UPDATE delta");
}
final H2Stream stream = streams.lookup(streamId);
if (stream != null) {
stream.localReset(new H2StreamResetException(H2Error.PROTOCOL_ERROR, "Invalid WINDOW_UPDATE delta"));
requestSessionOutput();
}
break;
}
if (streamId == 0) {
try {
Expand Down Expand Up @@ -947,6 +955,7 @@ private void consumeFrame(final RawFrame frame) throws HttpException, IOExceptio
throw new H2ConnectionException(H2Error.PROTOCOL_ERROR, "Illegal stream id");
}
if (frame.isFlagSet(FrameFlag.ACK)) {
// RFC 9113, Section 6.5: SETTINGS with ACK set MUST have an empty payload.
final ByteBuffer payload = frame.getPayload();
if (payload != null && payload.hasRemaining()) {
throw new H2ConnectionException(H2Error.FRAME_SIZE_ERROR, "Invalid SETTINGS ACK payload");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,8 @@ void testZeroIncrement() throws Exception {
final RawFrame incrementFrame = new RawFrame(FrameType.WINDOW_UPDATE.getValue(), 0, 1, payload);
outBuffer.write(incrementFrame, writableChannel);

final H2ConnectionException exception = Assertions.assertThrows(H2ConnectionException.class, () ->
Assertions.assertDoesNotThrow(() ->
streamMultiplexer.onInput(ByteBuffer.wrap(writableChannel.toByteArray())));
Assertions.assertEquals(H2Error.PROTOCOL_ERROR, H2Error.getByCode(exception.getCode()));
}

@Test
Expand Down Expand Up @@ -1810,4 +1809,58 @@ void testGoAwayReservedBitInLastStreamIdAffectsStreamCulling() throws Exception
Assertions.assertInstanceOf(org.apache.hc.core5.http.RequestNotExecutedException.class, exceptionCaptor.getValue());
}

@Test
void testWindowUpdateZeroIncrementOnConnectionIsConnectionError() throws Exception {
final AbstractH2StreamMultiplexer mux = new H2StreamMultiplexerImpl(
protocolIOSession,
FRAME_FACTORY,
StreamIdGenerator.ODD,
httpProcessor,
CharCodingConfig.DEFAULT,
H2Config.custom().build(),
h2StreamListener,
() -> streamHandler);

final ByteBuffer payload = ByteBuffer.allocate(4);
payload.putInt(0);
payload.flip();

final RawFrame windowUpdate = new RawFrame(FrameType.WINDOW_UPDATE.getValue(), 0, 0, payload);

final H2ConnectionException ex = Assertions.assertThrows(
H2ConnectionException.class,
() -> mux.onInput(ByteBuffer.wrap(encodeFrame(windowUpdate))));

Assertions.assertEquals(H2Error.PROTOCOL_ERROR, H2Error.getByCode(ex.getCode()));
}

@Test
void testWindowUpdateZeroIncrementOnStreamIsStreamError() throws Exception {
final AbstractH2StreamMultiplexer mux = new H2StreamMultiplexerImpl(
protocolIOSession,
FRAME_FACTORY,
StreamIdGenerator.ODD,
httpProcessor,
CharCodingConfig.DEFAULT,
H2Config.custom().build(),
h2StreamListener,
() -> streamHandler);

final H2StreamChannel channel = mux.createChannel(1);
mux.createStream(channel, streamHandler);

final ByteBuffer payload = ByteBuffer.allocate(4);
payload.putInt(0);
payload.flip();

final RawFrame windowUpdate = new RawFrame(FrameType.WINDOW_UPDATE.getValue(), 0, 1, payload);

Assertions.assertDoesNotThrow(() -> mux.onInput(ByteBuffer.wrap(encodeFrame(windowUpdate))));

Mockito.verify(streamHandler).failed(exceptionCaptor.capture());
final Exception cause = exceptionCaptor.getValue();
Assertions.assertInstanceOf(H2StreamResetException.class, cause);
Assertions.assertEquals(H2Error.PROTOCOL_ERROR, H2Error.getByCode(((H2StreamResetException) cause).getCode()));
}

}
Loading