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@24874a2

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
@@ -53,10 +53,13 @@
5353
import java.util.concurrent.atomic.AtomicBoolean;
5454

5555
import static io.netty.buffer.Unpooled.copiedBuffer;
56+
import static io.netty.handler.codec.http2.Http2CodecUtil.FRAME_HEADER_LENGTH;
5657
import static io.netty.handler.codec.http2.Http2CodecUtil.connectionPrefaceBuf;
58+
import static io.netty.handler.codec.http2.Http2CodecUtil.writeFrameHeaderInternal;
5759
import static io.netty.handler.codec.http2.Http2Error.CANCEL;
5860
import static io.netty.handler.codec.http2.Http2Error.PROTOCOL_ERROR;
5961
import static io.netty.handler.codec.http2.Http2Error.STREAM_CLOSED;
62+
import static io.netty.handler.codec.http2.Http2FrameTypes.SETTINGS;
6063
import static io.netty.handler.codec.http2.Http2Stream.State.CLOSED;
6164
import static io.netty.handler.codec.http2.Http2Stream.State.IDLE;
6265
import static io.netty.handler.codec.http2.Http2TestUtil.newVoidPromise;
@@ -329,6 +332,20 @@ public void serverReceivingInvalidClientPrefaceStringShouldHandleException() thr
329332
assertEquals(0, captor.getValue().refCnt());
330333
}
331334

335+
@Test
336+
public void serverReceivingInvalidClientSettingsAfterPrefaceShouldHandleException() throws Exception {
337+
ByteBuf buf = ctx.alloc().buffer(FRAME_HEADER_LENGTH);
338+
writeFrameHeaderInternal(buf, 0, SETTINGS, new Http2Flags().ack(true), 0);
339+
340+
when(connection.isServer()).thenReturn(true);
341+
handler = newHandler();
342+
handler.channelRead(ctx, Unpooled.wrappedBuffer(connectionPrefaceBuf(), buf));
343+
ArgumentCaptor<ByteBuf> captor = ArgumentCaptor.forClass(ByteBuf.class);
344+
verify(frameWriter).writeGoAway(eq(ctx), eq(Integer.MAX_VALUE), eq(PROTOCOL_ERROR.code()),
345+
captor.capture(), eq(promise));
346+
assertEquals(0, captor.getValue().refCnt());
347+
}
348+
332349
@Test
333350
public void serverReceivingHttp1ClientPrefaceStringShouldIncludePreface() throws Exception {
334351
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.