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 — Improve exception message when first HTTP2SettingsFrame has the ack f… · netty/netty@0ef1bb2

File tree

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

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

Copy file name to clipboardExpand all lines: codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionHandler.java
+11-2Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ public void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) thro
248248
byteDecoder.decode(ctx, in, out);
249249
}
250250
} catch (Throwable e) {
251+
if (byteDecoder != null) {
252+
// Skip all bytes before we report the exception as
253+
in.skipBytes(in.readableBytes());
254+
}
251255
onError(ctx, false, e);
252256
}
253257
}
@@ -346,12 +350,17 @@ private boolean verifyFirstFrameIsSettings(ByteBuf in) throws Http2Exception {
346350
}
347351

348352
short frameType = in.getUnsignedByte(in.readerIndex() + 3);
349-
short flags = in.getUnsignedByte(in.readerIndex() + 4);
350-
if (frameType != SETTINGS || (flags & Http2Flags.ACK) != 0) {
353+
if (frameType != SETTINGS) {
351354
throw connectionError(PROTOCOL_ERROR, "First received frame was not SETTINGS. " +
352355
"Hex dump for first 5 bytes: %s",
353356
hexDump(in, in.readerIndex(), 5));
354357
}
358+
short flags = in.getUnsignedByte(in.readerIndex() + 4);
359+
if ((flags & Http2Flags.ACK) != 0) {
360+
throw connectionError(PROTOCOL_ERROR, "First received frame was SETTINGS frame but had ACK flag set. " +
361+
"Hex dump for first 5 bytes: %s",
362+
hexDump(in, in.readerIndex(), 5));
363+
}
355364
return true;
356365
}
357366

Collapse file

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

Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionHandlerTest.java
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@
4646
import java.util.concurrent.atomic.AtomicBoolean;
4747

4848
import static io.netty.buffer.Unpooled.copiedBuffer;
49+
import static io.netty.handler.codec.http2.Http2CodecUtil.FRAME_HEADER_LENGTH;
4950
import static io.netty.handler.codec.http2.Http2CodecUtil.connectionPrefaceBuf;
51+
import static io.netty.handler.codec.http2.Http2CodecUtil.writeFrameHeaderInternal;
5052
import static io.netty.handler.codec.http2.Http2Error.CANCEL;
5153
import static io.netty.handler.codec.http2.Http2Error.PROTOCOL_ERROR;
5254
import static io.netty.handler.codec.http2.Http2Error.STREAM_CLOSED;
55+
import static io.netty.handler.codec.http2.Http2FrameTypes.SETTINGS;
5356
import static io.netty.handler.codec.http2.Http2Stream.State.CLOSED;
5457
import static io.netty.handler.codec.http2.Http2Stream.State.IDLE;
5558
import static io.netty.util.CharsetUtil.US_ASCII;
@@ -298,6 +301,20 @@ public void serverReceivingInvalidClientPrefaceStringShouldHandleException() thr
298301
assertEquals(0, captor.getValue().refCnt());
299302
}
300303

304+
@Test
305+
public void serverReceivingInvalidClientSettingsAfterPrefaceShouldHandleException() throws Exception {
306+
ByteBuf buf = ctx.alloc().buffer(FRAME_HEADER_LENGTH);
307+
writeFrameHeaderInternal(buf, 0, SETTINGS, new Http2Flags().ack(true), 0);
308+
309+
when(connection.isServer()).thenReturn(true);
310+
handler = newHandler();
311+
handler.channelRead(ctx, Unpooled.wrappedBuffer(connectionPrefaceBuf(), buf));
312+
ArgumentCaptor<ByteBuf> captor = ArgumentCaptor.forClass(ByteBuf.class);
313+
verify(frameWriter).writeGoAway(eq(ctx), eq(Integer.MAX_VALUE), eq(PROTOCOL_ERROR.code()),
314+
captor.capture(), eq(promise));
315+
assertEquals(0, captor.getValue().refCnt());
316+
}
317+
301318
@Test
302319
public void serverReceivingHttp1ClientPrefaceStringShouldIncludePreface() throws Exception {
303320
when(connection.isServer()).thenReturn(true);

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.