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 — Merge branch '4.2' into jdkzlib-gzip-id2 · netty/netty@fd8f851

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-classes-quic/src/main/java/io/netty/handler/codec/quic
    • SipHash.java
  • codec-http2/src/test/java/io/netty/handler/codec/http2
    • HpackDecoderTest.java
    • Http2MultiplexTest.java
  • codec-http/src
    • main/java/io/netty/handler/codec/http
      • ReadOnlyHttpHeaders.java
    • test/java/io/netty/handler/codec/http
      • HttpContentCompressorTest.java
      • ReadOnlyHttpHeadersTest.java
  • codec-native-quic/src/test/java/io/netty/handler/codec/quic
    • SipHashTest.java
  • common/src
    • main/java/io/netty/util
      • AsciiString.java
    • test/java/io/netty/util
      • AsciiStringCharacterTest.java
  • testsuite/src/main/java/io/netty/testsuite/transport/socket
    • DatagramUnicastIPv6MappedTest.java
    • DatagramUnicastTest.java
  • transport/src
    • main/java/io/netty/channel/socket/nio
      • NioDatagramChannelConfig.java
    • test/java/io/netty/channel/socket/nio
      • NioDatagramChannelTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: codec-classes-quic/src/main/java/io/netty/handler/codec/quic/SipHash.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ long macHash(ByteBuffer input) {
7575
int position = input.position();
7676
int len = remaining - (remaining % Long.BYTES);
7777
boolean needsReverse = input.order() == ByteOrder.BIG_ENDIAN;
78-
for (int offset = position; offset < len; offset += Long.BYTES) {
78+
for (int offset = position; offset < position + len; offset += Long.BYTES) {
7979
long m = input.getLong(offset);
8080
if (needsReverse) {
8181
// We use little-endian as in the paper.
Collapse file

‎codec-http/src/main/java/io/netty/handler/codec/http/ReadOnlyHttpHeaders.java‎

Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/http/ReadOnlyHttpHeaders.java
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ private final class ReadOnlyStringValueIterator implements Iterator<String> {
383383
ReadOnlyStringValueIterator(CharSequence name) {
384384
this.name = name;
385385
nameHash = AsciiString.hashCode(name);
386-
nextNameIndex = findNextValue();
386+
nextNameIndex = findNextValue(0);
387387
}
388388

389389
@Override
@@ -397,7 +397,7 @@ public String next() {
397397
throw new NoSuchElementException();
398398
}
399399
String value = nameValuePairs[nextNameIndex + 1].toString();
400-
nextNameIndex = findNextValue();
400+
nextNameIndex = findNextValue(nextNameIndex + 2);
401401
return value;
402402
}
403403

@@ -406,8 +406,8 @@ public void remove() {
406406
throw new UnsupportedOperationException("read only");
407407
}
408408

409-
private int findNextValue() {
410-
for (int i = nextNameIndex; i < nameValuePairs.length; i += 2) {
409+
private int findNextValue(int fromIndex) {
410+
for (int i = fromIndex; i < nameValuePairs.length; i += 2) {
411411
final CharSequence roName = nameValuePairs[i];
412412
if (nameHash == AsciiString.hashCode(roName) && contentEqualsIgnoreCase(name, roName)) {
413413
return i;
@@ -425,7 +425,7 @@ private final class ReadOnlyValueIterator implements Iterator<CharSequence> {
425425
ReadOnlyValueIterator(CharSequence name) {
426426
this.name = name;
427427
nameHash = AsciiString.hashCode(name);
428-
nextNameIndex = findNextValue();
428+
nextNameIndex = findNextValue(0);
429429
}
430430

431431
@Override
@@ -439,7 +439,7 @@ public CharSequence next() {
439439
throw new NoSuchElementException();
440440
}
441441
CharSequence value = nameValuePairs[nextNameIndex + 1];
442-
nextNameIndex = findNextValue();
442+
nextNameIndex = findNextValue(nextNameIndex + 2);
443443
return value;
444444
}
445445

@@ -448,8 +448,8 @@ public void remove() {
448448
throw new UnsupportedOperationException("read only");
449449
}
450450

451-
private int findNextValue() {
452-
for (int i = nextNameIndex; i < nameValuePairs.length; i += 2) {
451+
private int findNextValue(int fromIndex) {
452+
for (int i = fromIndex; i < nameValuePairs.length; i += 2) {
453453
final CharSequence roName = nameValuePairs[i];
454454
if (nameHash == AsciiString.hashCode(roName) && contentEqualsIgnoreCase(name, roName)) {
455455
return i;
Collapse file

‎codec-http/src/test/java/io/netty/handler/codec/http/HttpContentCompressorTest.java‎

Copy file name to clipboardExpand all lines: codec-http/src/test/java/io/netty/handler/codec/http/HttpContentCompressorTest.java
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,19 +489,19 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
489489

490490
client.writeAndFlush(newRequest()).sync();
491491

492-
assertEncodedResponse((HttpResponse) responses.poll(1, TimeUnit.SECONDS));
493-
HttpContent c = (HttpContent) responses.poll(1, TimeUnit.SECONDS);
492+
assertEncodedResponse((HttpResponse) responses.poll(5, TimeUnit.SECONDS));
493+
HttpContent c = (HttpContent) responses.poll(5, TimeUnit.SECONDS);
494494
assertNotNull(c);
495495
assertEquals("1f8b0800000000000000f248cdc9c9d75108cf2fca4901000000ffff",
496496
ByteBufUtil.hexDump(c.content()));
497497
c.release();
498498

499-
c = (HttpContent) responses.poll(1, TimeUnit.SECONDS);
499+
c = (HttpContent) responses.poll(5, TimeUnit.SECONDS);
500500
assertNotNull(c);
501501
assertEquals("0300c6865b260c000000", ByteBufUtil.hexDump(c.content()));
502502
c.release();
503503

504-
LastHttpContent last = (LastHttpContent) responses.poll(1, TimeUnit.SECONDS);
504+
LastHttpContent last = (LastHttpContent) responses.poll(5, TimeUnit.SECONDS);
505505
assertNotNull(last);
506506
assertEquals(0, last.content().readableBytes());
507507
last.release();
Collapse file

‎codec-http/src/test/java/io/netty/handler/codec/http/ReadOnlyHttpHeadersTest.java‎

Copy file name to clipboardExpand all lines: codec-http/src/test/java/io/netty/handler/codec/http/ReadOnlyHttpHeadersTest.java
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,30 @@ public void getAll() {
115115
assertTrue(APPLICATION_OCTET_STREAM.contentEqualsIgnoreCase(names.get(1)));
116116
}
117117

118+
@Test
119+
public void valueStringIterator() {
120+
ReadOnlyHttpHeaders headers = new ReadOnlyHttpHeaders(false,
121+
ACCEPT, APPLICATION_JSON, CONTENT_LENGTH, ZERO, ACCEPT, APPLICATION_OCTET_STREAM);
122+
Iterator<String> itr = headers.valueStringIterator(ACCEPT);
123+
assertTrue(itr.hasNext());
124+
assertTrue(APPLICATION_JSON.contentEqualsIgnoreCase(itr.next()));
125+
assertTrue(itr.hasNext());
126+
assertTrue(APPLICATION_OCTET_STREAM.contentEqualsIgnoreCase(itr.next()));
127+
assertFalse(itr.hasNext());
128+
}
129+
130+
@Test
131+
public void valueCharSequenceIterator() {
132+
ReadOnlyHttpHeaders headers = new ReadOnlyHttpHeaders(false,
133+
ACCEPT, APPLICATION_JSON, CONTENT_LENGTH, ZERO, ACCEPT, APPLICATION_OCTET_STREAM);
134+
Iterator<CharSequence> itr = headers.valueCharSequenceIterator(ACCEPT);
135+
assertTrue(itr.hasNext());
136+
assertTrue(APPLICATION_JSON.contentEqualsIgnoreCase(itr.next()));
137+
assertTrue(itr.hasNext());
138+
assertTrue(APPLICATION_OCTET_STREAM.contentEqualsIgnoreCase(itr.next()));
139+
assertFalse(itr.hasNext());
140+
}
141+
118142
@Test
119143
public void validateNamesFail() {
120144
assertThrows(IllegalArgumentException.class, new Executable() {
Collapse file

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

Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/HpackDecoderTest.java
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import io.netty.buffer.ByteBuf;
3535
import io.netty.buffer.Unpooled;
3636
import io.netty.util.AsciiString;
37+
import io.netty.util.CharsetUtil;
3738
import io.netty.util.internal.StringUtil;
3839
import org.junit.jupiter.api.BeforeEach;
3940
import org.junit.jupiter.api.Test;
@@ -825,6 +826,38 @@ public void execute() throws Throwable {
825826
}
826827
}
827828

829+
@Test
830+
public void receivedNonTokenHeaderNameIsRejected() throws Exception {
831+
String[] names = {"bad\r\nname", "bad\nname", "bad\rname", "bad\u0000name", "bad:name", "bad name",
832+
"bad;name", "bad\u00f0name", "Upper"};
833+
for (String name : names) {
834+
final ByteBuf in = Unpooled.buffer(200);
835+
try {
836+
HpackEncoder hpackEncoder = new HpackEncoder(true);
837+
838+
// Disable validation on the encode side so the invalid name makes it onto the wire.
839+
Http2Headers toEncode = new DefaultHttp2Headers(false);
840+
toEncode.add("foo", "bar");
841+
toEncode.add(new AsciiString(name.getBytes(CharsetUtil.ISO_8859_1)), AsciiString.of("v"));
842+
hpackEncoder.encodeHeaders(1, in, toEncode, NEVER_SENSITIVE);
843+
844+
final Http2Headers decoded = new DefaultHttp2Headers();
845+
846+
Http2Exception.StreamException e = assertThrows(Http2Exception.StreamException.class,
847+
new Executable() {
848+
@Override
849+
public void execute() throws Throwable {
850+
hpackDecoder.decode(3, in, decoded, true);
851+
}
852+
});
853+
assertEquals(3, e.streamId());
854+
assertEquals(PROTOCOL_ERROR, e.error());
855+
} finally {
856+
in.release();
857+
}
858+
}
859+
}
860+
828861
@Test
829862
public void failedValidationDoesntCorruptHpack() throws Exception {
830863
final ByteBuf in1 = Unpooled.buffer(200);
Collapse file

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

Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexTest.java
+5Lines changed: 5 additions & 0 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.UnpooledByteBufAllocator;
1819
import io.netty.buffer.Unpooled;
1920
import io.netty.channel.Channel;
2021
import io.netty.channel.ChannelFuture;
@@ -105,6 +106,10 @@ public abstract class Http2MultiplexTest<C extends Http2FrameCodec> {
105106
public void setUp() {
106107
childChannelInitializer = new TestChannelInitializer();
107108
parentChannel = new EmbeddedChannel();
109+
// Use an unpooled allocator as the tests verify the reference count of buffers after these were released.
110+
// Pooled buffers are recycled and so may be re-used by tests running in parallel, which makes it racy to
111+
// check the reference count of an already released buffer.
112+
parentChannel.config().setAllocator(UnpooledByteBufAllocator.DEFAULT);
108113
frameInboundWriter = new Http2FrameInboundWriter(parentChannel);
109114
parentChannel.connect(new InetSocketAddress(0));
110115
frameWriter = Http2TestUtil.mockedFrameWriter();
Collapse file

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

Copy file name to clipboardExpand all lines: codec-native-quic/src/test/java/io/netty/handler/codec/quic/SipHashTest.java
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import java.nio.ByteBuffer;
2424
import java.nio.ByteOrder;
25+
import java.util.Arrays;
2526
import java.util.concurrent.ThreadLocalRandom;
2627

2728
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -136,6 +137,25 @@ void testReferenceCases(ReferenceTestParam param) {
136137
assertEquals(param.expectedOutput, h);
137138
}
138139

140+
@ParameterizedTest
141+
@MethodSource("params")
142+
void testReferenceCasesWithPosition(ReferenceTestParam param) {
143+
SipHash hash = new SipHash(2, 4, REFERENCE_SEED);
144+
// Put the input at a non-zero position of a larger buffer.
145+
int position = 13;
146+
byte[] bytes = new byte[position + param.input.length + 7];
147+
Arrays.fill(bytes, (byte) 0x55);
148+
System.arraycopy(param.input, 0, bytes, position, param.input.length);
149+
150+
ByteBuffer heap = ByteBuffer.wrap(bytes, position, param.input.length);
151+
assertEquals(param.expectedOutput, hash.macHash(heap));
152+
153+
ByteBuffer direct = ByteBuffer.allocateDirect(bytes.length);
154+
direct.put(bytes).position(position).limit(position + param.input.length);
155+
assertEquals(param.expectedOutput, hash.macHash(direct));
156+
assertEquals(position, direct.position());
157+
}
158+
139159
@Test
140160
void testHash() {
141161
byte[] bytes = new byte[64];
Collapse file

‎common/src/main/java/io/netty/util/AsciiString.java‎

Copy file name to clipboardExpand all lines: common/src/main/java/io/netty/util/AsciiString.java
+4-13Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ public static CharSequence trim(CharSequence c) {
995995
if (start == 0 && end == last) {
996996
return c;
997997
}
998-
return c.subSequence(start, end);
998+
return c.subSequence(start, end + 1);
999999
}
10001000

10011001
/**
@@ -1584,18 +1584,9 @@ private static boolean contains(CharSequence a, CharSequence b, CharEqualityComp
15841584
if (b.length() == 0) {
15851585
return true;
15861586
}
1587-
int bStart = 0;
1588-
for (int i = 0; i < a.length(); ++i) {
1589-
if (cmp.equals(b.charAt(bStart), a.charAt(i))) {
1590-
// If b is consumed then true.
1591-
if (++bStart == b.length()) {
1592-
return true;
1593-
}
1594-
} else if (a.length() - i < b.length()) {
1595-
// If there are not enough characters left in a for b to be contained, then false.
1596-
return false;
1597-
} else {
1598-
bStart = 0;
1587+
for (int i = 0, last = a.length() - b.length(); i <= last; ++i) {
1588+
if (regionMatchesCharSequences(a, i, b, 0, b.length(), cmp)) {
1589+
return true;
15991590
}
16001591
}
16011592
return false;
Collapse file

‎common/src/test/java/io/netty/util/AsciiStringCharacterTest.java‎

Copy file name to clipboardExpand all lines: common/src/test/java/io/netty/util/AsciiStringCharacterTest.java
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ public void testContains() {
158158
assertContains(a, b, false, false);
159159
a += "0";
160160
assertContains(a, b, false, true);
161+
162+
assertContains("aab", "ab", true, true);
163+
assertContains("ababc", "abc", true, true);
164+
assertContains("xxYz", "xyz", false, true);
161165
}
162166

163167
private static void assertContains(String a, String b, boolean caseSensitiveEquals, boolean caseInsenstaiveEquals) {
@@ -303,6 +307,18 @@ public void testTrim() {
303307
assertEquals("abc", new AsciiString(" abc ").trim().toString());
304308
}
305309

310+
@Test
311+
public void testStaticTrimCharSequence() {
312+
// Neither String nor AsciiString, so the generic code path is used.
313+
assertEquals("abc", AsciiString.trim(new StringBuilder("abc")).toString());
314+
assertEquals("abc", AsciiString.trim(new StringBuilder(" abc")).toString());
315+
assertEquals("abc", AsciiString.trim(new StringBuilder("abc ")).toString());
316+
assertEquals("abc", AsciiString.trim(new StringBuilder(" abc ")).toString());
317+
assertEquals("a", AsciiString.trim(new StringBuilder(" a ")).toString());
318+
assertEquals("", AsciiString.trim(new StringBuilder("")).toString());
319+
assertEquals("", AsciiString.trim(new StringBuilder(" ")).toString());
320+
}
321+
306322
@Test
307323
public void testIndexOfChar() {
308324
assertEquals(-1, AsciiString.indexOf(null, 'a', 0));
Collapse file

‎testsuite/src/main/java/io/netty/testsuite/transport/socket/DatagramUnicastIPv6MappedTest.java‎

Copy file name to clipboardExpand all lines: testsuite/src/main/java/io/netty/testsuite/transport/socket/DatagramUnicastIPv6MappedTest.java
+62-5Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,79 @@
2020
import io.netty.util.NetUtil;
2121
import io.netty.util.internal.PlatformDependent;
2222

23-
import java.net.Inet4Address;
23+
import java.io.IOException;
24+
import java.io.UncheckedIOException;
25+
import java.net.BindException;
2426
import java.net.InetAddress;
2527
import java.net.InetSocketAddress;
2628
import java.net.SocketAddress;
29+
import java.net.StandardProtocolFamily;
2730
import java.net.UnknownHostException;
2831

2932
public class DatagramUnicastIPv6MappedTest extends DatagramUnicastIPv6Test {
3033

34+
private static final InetAddress IPV4_ANY;
35+
private static final int MAX_PORT_SELECTION_ATTEMPTS = 10;
36+
37+
static {
38+
try {
39+
IPV4_ANY = InetAddress.getByAddress(new byte[] {0, 0, 0, 0});
40+
} catch (UnknownHostException e) {
41+
throw new ExceptionInInitializerError(e);
42+
}
43+
}
44+
3145
@Override
3246
protected SocketAddress newSocketAddress() {
3347
// Explicit use IPv4 wildcard for bind while the channel is using SocketProtocolFamily.INET6.
34-
try {
35-
return new InetSocketAddress(InetAddress.getByAddress(new byte[] {0, 0 , 0, 0}), 0);
36-
} catch (UnknownHostException e) {
37-
throw new IllegalStateException(e);
48+
//
49+
// Don't use port 0: when an IPv6 socket binds to the wildcard address, macOS only checks the ports of other
50+
// IPv6 sockets when it selects the ephemeral port, so it might select a port that an IPv4 socket is
51+
// bound to. Datagrams that are sent to the IPv4 loopback address are then delivered to the IPv4 socket and
52+
// never reach the channel, no matter how often they are resent:
53+
//
54+
// - in6_pcbsetport() checks if the port is used with in6_pcblookup_local()...
55+
// https://github.com/apple-oss-distributions/xnu/blob/xnu-12377.121.6/bsd/netinet6/in6_src.c#L1779-L1780
56+
// - ...which skips all sockets that are not IPv6 sockets.
57+
// https://github.com/apple-oss-distributions/xnu/blob/xnu-12377.121.6/bsd/netinet6/in6_pcb.c#L1297-L1301
58+
// - The netns_reserve_in() check that follows only fails if Skywalk reserved the port, not BSD sockets.
59+
// https://github.com/apple-oss-distributions/xnu/blob/xnu-12377.121.6/bsd/skywalk/namespace/netns.c#L774-L783
60+
// - When an IPv4 datagram is received, in_pcblookup_hash_locked() prefers IPv4 sockets bound to the
61+
// destination or the wildcard address over IPv6 sockets bound to the wildcard address.
62+
// https://github.com/apple-oss-distributions/xnu/blob/xnu-12377.121.6/bsd/netinet/in_pcb.c#L2634-L2666
63+
return new InetSocketAddress(IPV4_ANY, unusedPort());
64+
}
65+
66+
/**
67+
* Returns a port that is neither used by an IPv4 nor by an IPv6 socket.
68+
*/
69+
private static int unusedPort() {
70+
BindException cause = null;
71+
for (int i = 0; i < MAX_PORT_SELECTION_ATTEMPTS; i++) {
72+
int port;
73+
// The IPv4 stack selects a port that is unused by IPv4 sockets and by IPv6 sockets that accept IPv4
74+
// datagrams.
75+
try (java.nio.channels.DatagramChannel ipv4 =
76+
java.nio.channels.DatagramChannel.open(StandardProtocolFamily.INET)) {
77+
ipv4.bind(new InetSocketAddress(IPV4_ANY, 0));
78+
port = ((InetSocketAddress) ipv4.getLocalAddress()).getPort();
79+
} catch (IOException e) {
80+
throw new UncheckedIOException(e);
81+
}
82+
// Bind to the port like the channel will do, which fails if an IPv6 socket that only accepts IPv6
83+
// datagrams uses it. The IPv4 channel must be closed by now, as this binds to the IPv4 wildcard address
84+
// as well on some platforms (like Linux).
85+
try (java.nio.channels.DatagramChannel ipv6 =
86+
java.nio.channels.DatagramChannel.open(StandardProtocolFamily.INET6)) {
87+
ipv6.bind(new InetSocketAddress(IPV4_ANY, port));
88+
return port;
89+
} catch (BindException e) {
90+
cause = e;
91+
} catch (IOException e) {
92+
throw new UncheckedIOException(e);
93+
}
3894
}
95+
throw new UncheckedIOException("Failed to find a port that is unused by IPv4 and IPv6 sockets", cause);
3996
}
4097

4198
@Override

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.