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 @@ -915,12 +915,14 @@ private void consumeFrame(final RawFrame frame) throws HttpException, IOExceptio
if (streamId == 0) {
throw new H2ConnectionException(H2Error.PROTOCOL_ERROR, "Illegal stream id: " + streamId);
}

final ByteBuffer payload = frame.getPayload();
if (payload == null || payload.remaining() != 4) {
throw new H2ConnectionException(H2Error.FRAME_SIZE_ERROR, "Invalid RST_STREAM frame payload");
}

final H2Stream stream = streams.lookupSeen(streamId);
if (stream != null) {
final ByteBuffer payload = frame.getPayload();
if (payload == null || payload.remaining() != 4) {
throw new H2ConnectionException(H2Error.FRAME_SIZE_ERROR, "Invalid RST_STREAM frame payload");
}
final int errorCode = payload.getInt();
if (errorCode == H2Error.NO_ERROR.getCode() && allowGracefulAbort(stream)) {
stream.abortGracefully();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1931,4 +1931,39 @@ void testFirstPeerSettingsAckRejected() throws Exception {
Assertions.assertEquals(H2Error.PROTOCOL_ERROR, H2Error.getByCode(ex.getCode()));
}

@Test
void testInputRstStreamWithInvalidLengthOnUnseenStreamRejected() throws Exception {
Mockito.when(protocolIOSession.write(ArgumentMatchers.any(ByteBuffer.class)))
.thenAnswer(invocation -> {
final ByteBuffer buffer = invocation.getArgument(0, ByteBuffer.class);
final int remaining = buffer.remaining();
buffer.position(buffer.limit());
return remaining;
});
Mockito.doNothing().when(protocolIOSession).setEvent(ArgumentMatchers.anyInt());
Mockito.doNothing().when(protocolIOSession).clearEvent(ArgumentMatchers.anyInt());

final AbstractH2StreamMultiplexer mux = new H2StreamMultiplexerImpl(
protocolIOSession,
FRAME_FACTORY,
StreamIdGenerator.ODD,
httpProcessor,
CharCodingConfig.DEFAULT,
H2Config.custom().build(),
h2StreamListener,
() -> streamHandler);

mux.onConnect();
completeSettingsHandshake(mux);

final RawFrame badRst = new RawFrame(FrameType.RST_STREAM.getValue(), 0, 1, null);

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

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


}
Loading