GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Drop unknown frame on missing stream in first packet (#15646) (#15647) · netty/netty@ebf9c55

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-http2/src
    • main/java/io/netty/handler/codec/http2
      • DefaultHttp2ConnectionDecoder.java
    • test/java/io/netty/handler/codec/http2
      • Http2FrameCodecTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java‎

Copy file name to clipboardExpand all lines: codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java
+3-7Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,6 @@ void onGoAwayRead0(ChannelHandlerContext ctx, int lastStreamId, long errorCode,
230230
connection.goAwayReceived(lastStreamId, errorCode, debugData);
231231
}
232232

233-
void onUnknownFrame0(ChannelHandlerContext ctx, byte frameType, int streamId, Http2Flags flags,
234-
ByteBuf payload) throws Http2Exception {
235-
listener.onUnknownFrame(ctx, frameType, streamId, flags, payload);
236-
}
237-
238233
// See https://tools.ietf.org/html/rfc7540#section-8.1.2.6
239234
private void verifyContentLength(Http2Stream stream, int data, boolean isEnd) throws Http2Exception {
240235
ContentLength contentLength = stream.getProperty(contentLengthKey);
@@ -633,7 +628,7 @@ public void onUnknownFrame(ChannelHandlerContext ctx, byte frameType, int stream
633628
return;
634629
}
635630

636-
onUnknownFrame0(ctx, frameType, streamId, flags, payload);
631+
listener.onUnknownFrame(ctx, frameType, streamId, flags, payload);
637632
}
638633

639634
/**
@@ -804,7 +799,8 @@ public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int wind
804799
@Override
805800
public void onUnknownFrame(ChannelHandlerContext ctx, byte frameType, int streamId, Http2Flags flags,
806801
ByteBuf payload) throws Http2Exception {
807-
onUnknownFrame0(ctx, frameType, streamId, flags, payload);
802+
verifyPrefaceReceived();
803+
internalFrameListener.onUnknownFrame(ctx, frameType, streamId, flags, payload);
808804
}
809805
}
810806

Collapse file

‎codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameCodecTest.java‎

Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameCodecTest.java
+54-8Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package io.netty.handler.codec.http2;
1616

1717
import io.netty.buffer.ByteBuf;
18+
import io.netty.buffer.CompositeByteBuf;
1819
import io.netty.buffer.Unpooled;
1920
import io.netty.channel.ChannelFuture;
2021
import io.netty.channel.ChannelFutureListener;
@@ -119,6 +120,11 @@ public void tearDown() throws Exception {
119120
}
120121

121122
private void setUp(Http2FrameCodecBuilder frameCodecBuilder, Http2Settings initialRemoteSettings) throws Exception {
123+
setUp(frameCodecBuilder, initialRemoteSettings, true);
124+
}
125+
126+
private void setUp(Http2FrameCodecBuilder frameCodecBuilder, Http2Settings initialRemoteSettings, boolean preface)
127+
throws Exception {
122128
/*
123129
* Some tests call this method twice. Once with JUnit's @Before and once directly to pass special settings.
124130
* This call ensures that in case of two consecutive calls to setUp(), the previous channel is shutdown and
@@ -142,18 +148,21 @@ private void setUp(Http2FrameCodecBuilder frameCodecBuilder, Http2Settings initi
142148
// Handshake
143149
verify(frameWriter).writeSettings(eqFrameCodecCtx(), anyHttp2Settings(), anyChannelPromise());
144150
verifyNoMoreInteractions(frameWriter);
145-
channel.writeInbound(Http2CodecUtil.connectionPrefaceBuf());
146151

147-
frameInboundWriter.writeInboundSettings(initialRemoteSettings);
152+
if (preface) {
153+
channel.writeInbound(Http2CodecUtil.connectionPrefaceBuf());
148154

149-
verify(frameWriter).writeSettingsAck(eqFrameCodecCtx(), anyChannelPromise());
155+
frameInboundWriter.writeInboundSettings(initialRemoteSettings);
150156

151-
frameInboundWriter.writeInboundSettingsAck();
157+
verify(frameWriter).writeSettingsAck(eqFrameCodecCtx(), anyChannelPromise());
152158

153-
Http2SettingsFrame settingsFrame = inboundHandler.readInbound();
154-
assertNotNull(settingsFrame);
155-
Http2SettingsAckFrame settingsAckFrame = inboundHandler.readInbound();
156-
assertNotNull(settingsAckFrame);
159+
frameInboundWriter.writeInboundSettingsAck();
160+
161+
Http2SettingsFrame settingsFrame = inboundHandler.readInbound();
162+
assertNotNull(settingsFrame);
163+
Http2SettingsAckFrame settingsAckFrame = inboundHandler.readInbound();
164+
assertNotNull(settingsAckFrame);
165+
}
157166
}
158167

159168
@Test
@@ -415,6 +424,43 @@ public void unknownFrameOnMissingStream() throws Exception {
415424
assertTrue(channel.isActive());
416425
}
417426

427+
@Test
428+
public void unknownFrameOnMissingStreamFirstPacket() throws Exception {
429+
setUp(Http2FrameCodecBuilder.forClient(), new Http2Settings(), false);
430+
431+
// SETTINGS and UNKNOWN must come in on the same packet to trigger the bug
432+
channel.pipeline().addFirst("combine", new ChannelInboundHandlerAdapter() {
433+
CompositeByteBuf accumulate;
434+
435+
@Override
436+
public void channelRead(ChannelHandlerContext ctx, Object msg) {
437+
if (accumulate == null) {
438+
accumulate = ctx.alloc().compositeBuffer();
439+
}
440+
accumulate.addComponent(true, (ByteBuf) msg);
441+
}
442+
443+
@Override
444+
public void handlerRemoved(ChannelHandlerContext ctx) {
445+
if (accumulate != null) {
446+
ctx.fireChannelRead(accumulate);
447+
ctx.fireChannelReadComplete();
448+
}
449+
}
450+
});
451+
452+
frameInboundWriter.writeInboundSettings(new Http2Settings());
453+
454+
ByteBuf debugData = bb("debug");
455+
frameInboundWriter.writeInboundFrame((byte) 0xb, 101, new Http2Flags(), debugData);
456+
457+
channel.pipeline().remove("combine");
458+
channel.flushInbound();
459+
460+
assertEquals(0, debugData.refCnt());
461+
assertTrue(channel.isActive());
462+
}
463+
418464
@Test
419465
public void goAwayLastStreamIdOverflowed() throws Exception {
420466
frameInboundWriter.writeInboundHeaders(5, request, 31, false);

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.