diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3ConnectionHandler.java b/src/main/java/io/netty/incubator/codec/http3/Http3ConnectionHandler.java index dbe6773..542e984 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3ConnectionHandler.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3ConnectionHandler.java @@ -71,8 +71,9 @@ public abstract class Http3ConnectionHandler extends ChannelInboundHandlerAdapte } Long maxFieldSectionSize = localSettings.get(Http3SettingsFrame.HTTP3_SETTINGS_MAX_FIELD_SECTION_SIZE); if (maxFieldSectionSize == null) { - // Just use the maximum value we can represent via a Long. - maxFieldSectionSize = Long.MAX_VALUE; + // Default value in rfc is unlimited + // but Quic can have max 2^62-1 max value as TWO bits reserved for Variable-Length Integer Encoding + maxFieldSectionSize = (1L << 62) - 1; } this.maxTableCapacity = localSettings.getOrDefault(HTTP3_SETTINGS_QPACK_MAX_TABLE_CAPACITY, 0); int maxBlockedStreams = toIntExact(localSettings.getOrDefault(HTTP3_SETTINGS_QPACK_BLOCKED_STREAMS, 0)); diff --git a/src/test/java/io/netty/incubator/codec/http3/EmbeddedQuicChannel.java b/src/test/java/io/netty/incubator/codec/http3/EmbeddedQuicChannel.java index 93900d5..d9e2b55 100644 --- a/src/test/java/io/netty/incubator/codec/http3/EmbeddedQuicChannel.java +++ b/src/test/java/io/netty/incubator/codec/http3/EmbeddedQuicChannel.java @@ -59,6 +59,17 @@ final class EmbeddedQuicChannel extends EmbeddedChannel implements QuicChannel { private static final AttributeKey streamIdGeneratorKey = valueOf("embedded_channel_stream_id_generator"); + + /** + * TWO bits reserved for Variable-Length Integer Encoding + * rfc9000 + * TWO LSB used for distinguish Client/Server initiated stream & Bi/unidirection + * these are not reserved but part of it + * rfc9000 + * so we can max stream per stream type (bi/uni) = (2^62-1)/2 + */ + private static final long MAX_PEER_STREAMS_PER_STREAM_TYPE = ((1L << 62) - 1) / 2; + private final Map peerAllowedStreams = new EnumMap<>(QuicStreamType.class); private final AtomicBoolean closed = new AtomicBoolean(); private final ConcurrentLinkedQueue closeErrorCodes = new ConcurrentLinkedQueue<>(); @@ -140,10 +151,13 @@ public QuicChannel read() { @Override public long peerAllowedStreams(QuicStreamType type) { - return peerAllowedStreams.getOrDefault(type, Long.MAX_VALUE); + return peerAllowedStreams.getOrDefault(type, MAX_PEER_STREAMS_PER_STREAM_TYPE); } public void peerAllowedStreams(QuicStreamType type, long peerAllowedStreams) { + if (peerAllowedStreams > MAX_PEER_STREAMS_PER_STREAM_TYPE) { + peerAllowedStreams = MAX_PEER_STREAMS_PER_STREAM_TYPE; + } this.peerAllowedStreams.put(type, peerAllowedStreams); }