forked from quic-go/quic-go
Merge pull request #462 from lucas-clemente/fix-461
fix detection of duplicate stream data in streamFrameSorter
This commit is contained in:
@@ -51,14 +51,13 @@ func (s *streamFrameSorter) Push(frame *frames.StreamFrame) error {
|
||||
start := frame.Offset
|
||||
end := frame.Offset + frame.DataLen()
|
||||
|
||||
// the frame is a duplicate. Ignore it
|
||||
if end <= s.gaps.Front().Value.Start {
|
||||
return errDuplicateStreamData
|
||||
}
|
||||
|
||||
// skip all gaps that are before this stream frame
|
||||
var gap *utils.ByteIntervalElement
|
||||
for gap = s.gaps.Front(); gap != nil; gap = gap.Next() {
|
||||
// the frame is a duplicate. Ignore it
|
||||
if end <= gap.Value.Start {
|
||||
return errDuplicateStreamData
|
||||
}
|
||||
if end > gap.Value.Start && start <= gap.Value.End {
|
||||
break
|
||||
}
|
||||
|
||||
@@ -512,7 +512,7 @@ var _ = Describe("StreamFrame sorter", func() {
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
// create gaps: 5-10, 15-20, 25-inf
|
||||
// create gaps: 5-10, 15-inf
|
||||
err := s.Push(&frames.StreamFrame{Offset: 0, Data: []byte("12345")})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = s.Push(&frames.StreamFrame{Offset: 10, Data: []byte("12345")})
|
||||
@@ -546,6 +546,22 @@ var _ = Describe("StreamFrame sorter", func() {
|
||||
Expect(s.queuedFrames).ToNot(HaveKey(protocol.ByteCount(1)))
|
||||
})
|
||||
|
||||
It("detects a duplicate frame that is smaller than the original, somewhere in the middle in the last block", func() {
|
||||
// 11 to 14
|
||||
err := s.Push(&frames.StreamFrame{Offset: 11, Data: []byte("123")})
|
||||
Expect(err).To(MatchError(errDuplicateStreamData))
|
||||
Expect(s.queuedFrames[10].Data).To(HaveLen(5))
|
||||
Expect(s.queuedFrames).ToNot(HaveKey(protocol.ByteCount(11)))
|
||||
})
|
||||
|
||||
It("detects a duplicate frame that is smaller than the original, with aligned end in the last block", func() {
|
||||
// 11 to 14
|
||||
err := s.Push(&frames.StreamFrame{Offset: 11, Data: []byte("1234")})
|
||||
Expect(err).To(MatchError(errDuplicateStreamData))
|
||||
Expect(s.queuedFrames[10].Data).To(HaveLen(5))
|
||||
Expect(s.queuedFrames).ToNot(HaveKey(protocol.ByteCount(11)))
|
||||
})
|
||||
|
||||
It("detects a duplicate frame that is smaller than the original, with aligned end", func() {
|
||||
// 3 to 5
|
||||
err := s.Push(&frames.StreamFrame{Offset: 3, Data: []byte("12")})
|
||||
|
||||
Reference in New Issue
Block a user