diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java index c71f2fb02..964ae61e4 100644 --- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java +++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java @@ -775,6 +775,9 @@ private void consumeFrame(final RawFrame frame) throws HttpException, IOExceptio if (continuation != null && frameType != FrameType.CONTINUATION) { throw new H2ConnectionException(H2Error.PROTOCOL_ERROR, "CONTINUATION frame expected"); } + if (frameType == null) { + return; + } switch (frameType) { case DATA: { if (streamId == 0) { diff --git a/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/nio/TestAbstractH2StreamMultiplexer.java b/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/nio/TestAbstractH2StreamMultiplexer.java index 67427bf2a..65d5493ec 100644 --- a/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/nio/TestAbstractH2StreamMultiplexer.java +++ b/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/nio/TestAbstractH2StreamMultiplexer.java @@ -1099,6 +1099,28 @@ void testOutboundTrailersWithPseudoHeaderRejected() throws Exception { Assertions.assertThrows(H2ConnectionException.class, () -> channel.endStream(trailers)); } + + @Test + void testInputUnknownFrameTypeIgnored() throws Exception { + final WritableByteChannelMock writableChannel = new WritableByteChannelMock(1024); + final FrameOutputBuffer outBuffer = new FrameOutputBuffer(16 * 1024); + + // 0x0a is not a defined HTTP/2 core frame type in FrameType enum (extension / unknown) + final RawFrame unknownFrame = new RawFrame(0x0a, 0, 0, ByteBuffer.allocate(0)); + outBuffer.write(unknownFrame, writableChannel); + + final AbstractH2StreamMultiplexer streamMultiplexer = new H2StreamMultiplexerImpl( + protocolIOSession, + FRAME_FACTORY, + StreamIdGenerator.ODD, + httpProcessor, + CharCodingConfig.DEFAULT, + H2Config.custom().build(), + h2StreamListener, + () -> streamHandler); + + Assertions.assertDoesNotThrow(() -> streamMultiplexer.onInput(ByteBuffer.wrap(writableChannel.toByteArray()))); + } private static byte[] encodeFrame(final RawFrame frame) throws IOException { final WritableByteChannelMock writableChannel = new WritableByteChannelMock(256); final FrameOutputBuffer outBuffer = new FrameOutputBuffer(16 * 1024);