diff --git a/internal/protocol/protocol.go b/internal/protocol/protocol.go index c18a2b65c..6e59afcb4 100644 --- a/internal/protocol/protocol.go +++ b/internal/protocol/protocol.go @@ -64,6 +64,10 @@ const MinStatelessResetSize = 1 /* first byte */ + 22 /* random bytes */ + 16 /* // MinConnectionIDLenInitial is the minimum length of the destination connection ID on an Initial packet. const MinConnectionIDLenInitial = 8 +// MaxStreamCount is the maximum stream count value that can be sent in MAX_STREAMS frames +// and as the stream count in the transport parameters +const MaxStreamCount = 1 << 60 + // DefaultAckDelayExponent is the default ack delay exponent const DefaultAckDelayExponent = 3 diff --git a/streams_map.go b/streams_map.go index b71953756..b47596de6 100644 --- a/streams_map.go +++ b/streams_map.go @@ -8,6 +8,7 @@ import ( "github.com/lucas-clemente/quic-go/internal/flowcontrol" "github.com/lucas-clemente/quic-go/internal/handshake" "github.com/lucas-clemente/quic-go/internal/protocol" + "github.com/lucas-clemente/quic-go/internal/qerr" "github.com/lucas-clemente/quic-go/internal/wire" ) @@ -159,6 +160,9 @@ func (m *streamsMap) GetOrOpenSendStream(id protocol.StreamID) (sendStreamI, err } func (m *streamsMap) HandleMaxStreamsFrame(f *wire.MaxStreamsFrame) error { + if f.MaxStreams > protocol.MaxStreamCount { + return qerr.StreamLimitError + } id := protocol.MaxStreamID(f.Type, f.MaxStreams, m.perspective) switch id.Type() { case protocol.StreamTypeUni: diff --git a/streams_map_test.go b/streams_map_test.go index 15df4c269..19f16b7bb 100644 --- a/streams_map_test.go +++ b/streams_map_test.go @@ -356,6 +356,13 @@ var _ = Describe("Streams Map", func() { _, err = m.OpenUniStream() expectTooManyStreamsError(err) }) + + It("rejects MAX_STREAMS frames with too large values", func() { + Expect(m.HandleMaxStreamsFrame(&wire.MaxStreamsFrame{ + Type: protocol.StreamTypeBidi, + MaxStreams: protocol.MaxStreamCount + 1, + })).To(MatchError(qerr.StreamLimitError)) + }) }) Context("sending MAX_STREAMS frames", func() {