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:
Marten Seemann
2019-08-31 17:13:40 +07:00
committed by GitHub
3 changed files with 18 additions and 2 deletions

View File

@@ -190,6 +190,17 @@ var _ = Describe("Transport Parameters", func() {
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() {
b := &bytes.Buffer{}
// write a known parameter

View File

@@ -139,6 +139,9 @@ func (p *TransportParameters) Unmarshal(data []byte, sentBy protocol.Perspective
if !readMaxAckDelay {
p.MaxAckDelay = protocol.DefaultMaxAckDelay
}
if p.MaxPacketSize == 0 {
p.MaxPacketSize = protocol.MaxByteCount
}
// check that every transport parameter was sent at most once
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 {
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
default:
return fmt.Errorf("TransportParameter BUG: transport parameter %d not found", paramID)

View File

@@ -3,7 +3,6 @@ package wire
import (
"bytes"
"errors"
"math"
"sort"
"time"
@@ -42,7 +41,7 @@ func parseAckFrame(r *bytes.Reader, ackDelayExponent uint8, version protocol.Ver
delayTime := time.Duration(delay*1<<ackDelayExponent) * time.Microsecond
if delayTime < 0 {
// If the delay time overflows, set it to the maximum encodable value.
delayTime = time.Duration(math.MaxInt64)
delayTime = utils.InfDuration
}
frame.DelayTime = delayTime