forked from quic-go/quic-go
Merge pull request #2092 from lucas-clemente/max-ack-delay-overflow
handle negative max_ack_delay values in the transport parameters
This commit is contained in:
@@ -190,6 +190,17 @@ var _ = Describe("Transport Parameters", func() {
|
|||||||
Expect(err.Error()).To(ContainSubstring("inconsistent transport parameter length"))
|
Expect(err.Error()).To(ContainSubstring("inconsistent transport parameter length"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("handles max_ack_delays that decode to a negative duration", func() {
|
||||||
|
b := &bytes.Buffer{}
|
||||||
|
val := uint64(math.MaxUint64) / 5
|
||||||
|
utils.BigEndian.WriteUint16(b, uint16(maxAckDelayParameterID))
|
||||||
|
utils.BigEndian.WriteUint16(b, uint16(utils.VarIntLen(val)))
|
||||||
|
utils.WriteVarInt(b, val)
|
||||||
|
p := &TransportParameters{}
|
||||||
|
Expect(p.Unmarshal(prependLength(b.Bytes()), protocol.PerspectiveServer)).To(Succeed())
|
||||||
|
Expect(p.MaxAckDelay).To(BeNumerically(">", 290*365*24*time.Hour))
|
||||||
|
})
|
||||||
|
|
||||||
It("skips unknown parameters", func() {
|
It("skips unknown parameters", func() {
|
||||||
b := &bytes.Buffer{}
|
b := &bytes.Buffer{}
|
||||||
// write a known parameter
|
// write a known parameter
|
||||||
|
|||||||
@@ -139,6 +139,9 @@ func (p *TransportParameters) Unmarshal(data []byte, sentBy protocol.Perspective
|
|||||||
if !readMaxAckDelay {
|
if !readMaxAckDelay {
|
||||||
p.MaxAckDelay = protocol.DefaultMaxAckDelay
|
p.MaxAckDelay = protocol.DefaultMaxAckDelay
|
||||||
}
|
}
|
||||||
|
if p.MaxPacketSize == 0 {
|
||||||
|
p.MaxPacketSize = protocol.MaxByteCount
|
||||||
|
}
|
||||||
|
|
||||||
// check that every transport parameter was sent at most once
|
// check that every transport parameter was sent at most once
|
||||||
sort.Slice(parameterIDs, func(i, j int) bool { return parameterIDs[i] < parameterIDs[j] })
|
sort.Slice(parameterIDs, func(i, j int) bool { return parameterIDs[i] < parameterIDs[j] })
|
||||||
@@ -197,6 +200,9 @@ func (p *TransportParameters) readNumericTransportParameter(
|
|||||||
if maxAckDelay >= protocol.MaxMaxAckDelay {
|
if maxAckDelay >= protocol.MaxMaxAckDelay {
|
||||||
return fmt.Errorf("invalid value for max_ack_delay: %dms (maximum %dms)", maxAckDelay/time.Millisecond, (protocol.MaxMaxAckDelay-time.Millisecond)/time.Millisecond)
|
return fmt.Errorf("invalid value for max_ack_delay: %dms (maximum %dms)", maxAckDelay/time.Millisecond, (protocol.MaxMaxAckDelay-time.Millisecond)/time.Millisecond)
|
||||||
}
|
}
|
||||||
|
if maxAckDelay < 0 {
|
||||||
|
maxAckDelay = utils.InfDuration
|
||||||
|
}
|
||||||
p.MaxAckDelay = maxAckDelay
|
p.MaxAckDelay = maxAckDelay
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("TransportParameter BUG: transport parameter %d not found", paramID)
|
return fmt.Errorf("TransportParameter BUG: transport parameter %d not found", paramID)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package wire
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"math"
|
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -42,7 +41,7 @@ func parseAckFrame(r *bytes.Reader, ackDelayExponent uint8, version protocol.Ver
|
|||||||
delayTime := time.Duration(delay*1<<ackDelayExponent) * time.Microsecond
|
delayTime := time.Duration(delay*1<<ackDelayExponent) * time.Microsecond
|
||||||
if delayTime < 0 {
|
if delayTime < 0 {
|
||||||
// If the delay time overflows, set it to the maximum encodable value.
|
// If the delay time overflows, set it to the maximum encodable value.
|
||||||
delayTime = time.Duration(math.MaxInt64)
|
delayTime = utils.InfDuration
|
||||||
}
|
}
|
||||||
frame.DelayTime = delayTime
|
frame.DelayTime = delayTime
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user