Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit ac684de

Browse files
authored
Limit QUIC stream and field section sizes to protocol max (#356)
Updated the default maxFieldSectionSize in Http3ConnectionHandler to (2^62) - 1, aligning with QUIC variable-length integer limits defined in RFC 9000. Introduced MAX_PEER_STREAMS_PER_STREAM_TYPE in EmbeddedQuicChannel and enforced this maximum for peer allowed streams, ensuring compliance with QUIC stream identifier constraints. **Motivation** QUIC uses 62-bit variable-length integers, allowing values up to (2^62) - 1. The previous default did not fully reflect this limit. Additionally, peer stream limits are applied per stream direction and initiator, but the current stream type model arbitrarily uses or allows Long.MAX_VALUE. This required enforcing a corrected maximum per stream type. **Modification** Set maxFieldSectionSize default to (2^62) - 1. Introduced MAX_PEER_STREAMS_PER_STREAM_TYPE to ((1L << 62) - 1) / 2 Enforced the maximum when storing peer allowed stream counts. **Result** Aligns HTTP/3 settings and peer stream limits with RFC 9000 and prevents invalid stream allocations. This is a port of netty/netty#16117
1 parent 4374490 commit ac684de

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/main/java/io/netty/incubator/codec/http3/Http3ConnectionHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ public abstract class Http3ConnectionHandler extends ChannelInboundHandlerAdapte
7171
}
7272
Long maxFieldSectionSize = localSettings.get(Http3SettingsFrame.HTTP3_SETTINGS_MAX_FIELD_SECTION_SIZE);
7373
if (maxFieldSectionSize == null) {
74-
// Just use the maximum value we can represent via a Long.
75-
maxFieldSectionSize = Long.MAX_VALUE;
74+
// Default value in rfc is unlimited
75+
// but Quic can have max 2^62-1 max value as TWO bits reserved for Variable-Length Integer Encoding
76+
maxFieldSectionSize = (1L << 62) - 1;
7677
}
7778
this.maxTableCapacity = localSettings.getOrDefault(HTTP3_SETTINGS_QPACK_MAX_TABLE_CAPACITY, 0);
7879
int maxBlockedStreams = toIntExact(localSettings.getOrDefault(HTTP3_SETTINGS_QPACK_BLOCKED_STREAMS, 0));

src/test/java/io/netty/incubator/codec/http3/EmbeddedQuicChannel.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@
5959
final class EmbeddedQuicChannel extends EmbeddedChannel implements QuicChannel {
6060
private static final AttributeKey<AtomicLong> streamIdGeneratorKey =
6161
valueOf("embedded_channel_stream_id_generator");
62+
63+
/**
64+
* TWO bits reserved for Variable-Length Integer Encoding
65+
* <a href="https://datatracker.ietf.org/doc/html/rfc9000?#name-variable-length-integer-enc">rfc9000</a>
66+
* TWO LSB used for distinguish Client/Server initiated stream & Bi/unidirection
67+
* these are not reserved but part of it
68+
* <a href="https://datatracker.ietf.org/doc/html/rfc9000?#name-stream-types-and-identifier">rfc9000</a>
69+
* so we can max stream per stream type (bi/uni) = (2^62-1)/2
70+
*/
71+
private static final long MAX_PEER_STREAMS_PER_STREAM_TYPE = ((1L << 62) - 1) / 2;
72+
6273
private final Map<QuicStreamType, Long> peerAllowedStreams = new EnumMap<>(QuicStreamType.class);
6374
private final AtomicBoolean closed = new AtomicBoolean();
6475
private final ConcurrentLinkedQueue<Integer> closeErrorCodes = new ConcurrentLinkedQueue<>();
@@ -140,10 +151,13 @@ public QuicChannel read() {
140151

141152
@Override
142153
public long peerAllowedStreams(QuicStreamType type) {
143-
return peerAllowedStreams.getOrDefault(type, Long.MAX_VALUE);
154+
return peerAllowedStreams.getOrDefault(type, MAX_PEER_STREAMS_PER_STREAM_TYPE);
144155
}
145156

146157
public void peerAllowedStreams(QuicStreamType type, long peerAllowedStreams) {
158+
if (peerAllowedStreams > MAX_PEER_STREAMS_PER_STREAM_TYPE) {
159+
peerAllowedStreams = MAX_PEER_STREAMS_PER_STREAM_TYPE;
160+
}
147161
this.peerAllowedStreams.put(type, peerAllowedStreams);
148162
}
149163

0 commit comments

Comments
 (0)