From 17865dbba7c861cfb69d995002fd9b2b529deeb0 Mon Sep 17 00:00:00 2001 From: Lucas Clemente Date: Wed, 25 May 2016 13:12:06 +0200 Subject: [PATCH] fix a panic in stream with large window updates fixes #143 --- stream.go | 4 ++-- stream_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/stream.go b/stream.go index 4af37f01..fdc51ed2 100644 --- a/stream.go +++ b/stream.go @@ -200,7 +200,7 @@ func (s *stream) Write(p []byte) (int, error) { return 0, s.err } - dataLen := utils.Min(len(p), int(remainingBytesInWindow)) + dataLen := utils.MinByteCount(protocol.ByteCount(len(p)), remainingBytesInWindow) data := make([]byte, dataLen) copy(data, p) err := s.session.queueStreamFrame(&frames.StreamFrame{ @@ -213,7 +213,7 @@ func (s *stream) Write(p []byte) (int, error) { return 0, err } - dataWritten += dataLen + dataWritten += int(dataLen) // We cannot have written more than the int range s.flowController.AddBytesSent(protocol.ByteCount(dataLen)) if s.contributesToConnectionFlowControl { s.connectionFlowController.AddBytesSent(protocol.ByteCount(dataLen)) diff --git a/stream_test.go b/stream_test.go index e1eef2ff..bff4bea3 100644 --- a/stream_test.go +++ b/stream_test.go @@ -464,6 +464,16 @@ var _ = Describe("Stream", func() { Expect(b).To(BeTrue()) Expect(err).To(MatchError(testErr)) }) + + It("works with large flow control windows", func() { + // This paniced before due to a wrong cast, + // see https://github.com/lucas-clemente/quic-go/issues/143 + str.contributesToConnectionFlowControl = false + updated := str.UpdateSendFlowControlWindow(protocol.ByteCount(1) << 63) + Expect(updated).To(BeTrue()) + _, err := str.Write([]byte("foobar")) + Expect(err).NotTo(HaveOccurred()) + }) }) })