correctly parse ACK frames with LargestAcked 0

fixes #362
This commit is contained in:
Marten Seemann 2016-12-02 22:32:10 +07:00
parent 3c7872c7b3
commit 295f6c78d9
No known key found for this signature in database
GPG key ID: 3603F40B121FCDEA
2 changed files with 16 additions and 2 deletions

View file

@ -83,7 +83,7 @@ func ParseAckFrame(r *bytes.Reader, version protocol.VersionNumber) (*AckFrame,
if err != nil {
return nil, err
}
if ackBlockLength < 1 {
if frame.LargestAcked > 0 && ackBlockLength < 1 {
return nil, ErrInvalidFirstAckRange
}
@ -141,7 +141,11 @@ func ParseAckFrame(r *bytes.Reader, version protocol.VersionNumber) (*AckFrame,
frame.LowestAcked = frame.AckRanges[len(frame.AckRanges)-1].FirstPacketNumber
} else {
frame.LowestAcked = protocol.PacketNumber(largestAcked + 1 - ackBlockLength)
if frame.LargestAcked == 0 {
frame.LowestAcked = 0
} else {
frame.LowestAcked = protocol.PacketNumber(largestAcked + 1 - ackBlockLength)
}
}
if !frame.validateAckRanges() {

View file

@ -29,6 +29,16 @@ var _ = Describe("AckFrame", func() {
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(3)))
})
It("parses a frame where the largest acked is 0", func() {
b := bytes.NewReader([]byte{0x40, 0x0, 0xff, 0xff, 0x0, 0x0})
frame, err := ParseAckFrame(b, 0)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0)))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(0)))
Expect(frame.HasMissingRanges()).To(BeFalse())
Expect(b.Len()).To(BeZero())
})
It("parses a frame with a 48 bit packet number", func() {
b := bytes.NewReader([]byte{0x4c, 0x37, 0x13, 0xad, 0xfb, 0xca, 0xde, 0x0, 0x0, 0x5, 0x1, 0, 0, 0, 0, 0})
frame, err := ParseAckFrame(b, 0)