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 — Port 5.0: Don't use a negative index in QuicCodecDispatcher (#18048) … · netty/netty@bdae6a2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-classes-quic/src/main/java/io/netty/handler/codec/quic
    • QuicCodecDispatcher.java
  • codec-native-quic/src/test/java/io/netty/handler/codec/quic
    • QuicCodecDispatcherTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicCodecDispatcher.java‎

Copy file name to clipboardExpand all lines: codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicCodecDispatcher.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ public final void channelRead(ChannelHandlerContext ctx, Object msg) throws Exce
116116
ByteBuf connectionId = getDestinationConnectionId(packet.content(), localConnectionIdLength);
117117
if (connectionId != null) {
118118
int idx = decodeIndex(connectionId);
119-
if (contextList.size() > idx) {
119+
// decodeIndex(...) returns -1 if decoding was not successful.
120+
if (idx >= 0 && contextList.size() > idx) {
120121
ChannelHandlerContextDispatcher selectedCtx = contextList.get(idx);
121122
if (selectedCtx != null) {
122123
selectedCtx.fireChannelRead(msg);
Collapse file

‎codec-native-quic/src/test/java/io/netty/handler/codec/quic/QuicCodecDispatcherTest.java‎

Copy file name to clipboardExpand all lines: codec-native-quic/src/test/java/io/netty/handler/codec/quic/QuicCodecDispatcherTest.java
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import static org.junit.jupiter.api.Assertions.assertFalse;
3232
import static org.junit.jupiter.api.Assertions.assertNotNull;
3333
import static org.junit.jupiter.api.Assertions.assertNull;
34+
import static org.junit.jupiter.api.Assertions.assertSame;
35+
import static org.junit.jupiter.api.Assertions.assertTrue;
3436

3537
public class QuicCodecDispatcherTest {
3638

@@ -88,6 +90,33 @@ protected void initChannel(Channel channel, int localConnectionIdLength,
8890
assertEquals(channels.length, initChannelCalled.get());
8991
}
9092

93+
@Test
94+
public void testPacketIsForwardedIfIndexCanNotBeDecoded() throws Exception {
95+
short localConnectionIdLength = 16;
96+
97+
QuicCodecDispatcher dispatcher = new QuicCodecDispatcher(localConnectionIdLength) {
98+
@Override
99+
protected void initChannel(Channel channel, int localConnectionIdLength,
100+
QuicConnectionIdGenerator idGenerator) {
101+
// NOOP
102+
}
103+
104+
@Override
105+
protected int decodeIndex(ByteBuf connectionId) {
106+
return -1;
107+
}
108+
};
109+
EmbeddedChannel channel = new EmbeddedChannel(dispatcher);
110+
111+
// Use a packet with a short header so we try to decode the index.
112+
DatagramPacket packet = createQuicPacket(0, true, localConnectionIdLength);
113+
assertTrue(channel.writeInbound(packet));
114+
DatagramPacket forwarded = channel.readInbound();
115+
assertSame(packet, forwarded);
116+
forwarded.release();
117+
assertFalse(channel.finishAndReleaseAll());
118+
}
119+
91120
private static void writePacket(EmbeddedChannel[] channels, boolean shortHeader, short localConnectionIdLength)
92121
throws Exception {
93122
DatagramPacket packet = createQuicPacket(

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.