diff --git a/vendor/github.com/lucas-clemente/quic-go/internal/wire/header.go b/vendor/github.com/lucas-clemente/quic-go/internal/wire/header.go index 03d338ab..36255fdd 100644 --- a/vendor/github.com/lucas-clemente/quic-go/internal/wire/header.go +++ b/vendor/github.com/lucas-clemente/quic-go/internal/wire/header.go @@ -28,7 +28,7 @@ type Header struct { Type protocol.PacketType IsLongHeader bool KeyPhase int - PayloadLen protocol.ByteCount + Length protocol.ByteCount Token []byte } @@ -72,7 +72,7 @@ func (h *Header) writeLongHeader(b *bytes.Buffer, v protocol.VersionNumber) erro return nil } - utils.WriteVarInt(b, uint64(h.PayloadLen)) + utils.WriteVarInt(b, uint64(h.Length)) return utils.WriteVarIntPacketNumber(b, h.PacketNumber, h.PacketNumberLen) } @@ -88,7 +88,7 @@ func (h *Header) writeShortHeader(b *bytes.Buffer, v protocol.VersionNumber) err // GetLength determines the length of the Header. func (h *Header) GetLength(v protocol.VersionNumber) protocol.ByteCount { if h.IsLongHeader { - length := 1 /* type byte */ + 4 /* version */ + 1 /* conn id len byte */ + protocol.ByteCount(h.DestConnectionID.Len()+h.SrcConnectionID.Len()) + protocol.ByteCount(h.PacketNumberLen) + utils.VarIntLen(uint64(h.PayloadLen)) + length := 1 /* type byte */ + 4 /* version */ + 1 /* conn id len byte */ + protocol.ByteCount(h.DestConnectionID.Len()+h.SrcConnectionID.Len()) + protocol.ByteCount(h.PacketNumberLen) + utils.VarIntLen(uint64(h.Length)) if h.Type == protocol.PacketTypeInitial { length += utils.VarIntLen(uint64(len(h.Token))) + protocol.ByteCount(len(h.Token)) } @@ -118,7 +118,7 @@ func (h *Header) Log(logger utils.Logger) { logger.Debugf("\tLong Header{Type: %s, DestConnectionID: %s, SrcConnectionID: %s, %sOrigDestConnectionID: %s, Version: %s}", h.Type, h.DestConnectionID, h.SrcConnectionID, token, h.OrigDestConnectionID, h.Version) return } - logger.Debugf("\tLong Header{Type: %s, DestConnectionID: %s, SrcConnectionID: %s, %sPacketNumber: %#x, PacketNumberLen: %d, PayloadLen: %d, Version: %s}", h.Type, h.DestConnectionID, h.SrcConnectionID, token, h.PacketNumber, h.PacketNumberLen, h.PayloadLen, h.Version) + logger.Debugf("\tLong Header{Type: %s, DestConnectionID: %s, SrcConnectionID: %s, %sPacketNumber: %#x, PacketNumberLen: %d, Length: %d, Version: %s}", h.Type, h.DestConnectionID, h.SrcConnectionID, token, h.PacketNumber, h.PacketNumberLen, h.Length, h.Version) } } else { logger.Debugf("\tShort Header{DestConnectionID: %s, PacketNumber: %#x, PacketNumberLen: %d, KeyPhase: %d}", h.DestConnectionID, h.PacketNumber, h.PacketNumberLen, h.KeyPhase) diff --git a/vendor/github.com/lucas-clemente/quic-go/internal/wire/header_parser.go b/vendor/github.com/lucas-clemente/quic-go/internal/wire/header_parser.go index f90a50c9..ce1ec0d9 100644 --- a/vendor/github.com/lucas-clemente/quic-go/internal/wire/header_parser.go +++ b/vendor/github.com/lucas-clemente/quic-go/internal/wire/header_parser.go @@ -141,7 +141,7 @@ func (iv *InvariantHeader) parseLongHeader(b *bytes.Reader, sentBy protocol.Pers if err != nil { return nil, err } - h.PayloadLen = protocol.ByteCount(pl) + h.Length = protocol.ByteCount(pl) pn, pnLen, err := utils.ReadVarIntPacketNumber(b) if err != nil { return nil, err diff --git a/vendor/github.com/lucas-clemente/quic-go/packet_handler_map.go b/vendor/github.com/lucas-clemente/quic-go/packet_handler_map.go index 784dced3..a4acb6fd 100644 --- a/vendor/github.com/lucas-clemente/quic-go/packet_handler_map.go +++ b/vendor/github.com/lucas-clemente/quic-go/packet_handler_map.go @@ -216,10 +216,13 @@ func (h *packetHandlerMap) handlePacket(addr net.Addr, data []byte) error { packetData := data[len(data)-r.Len():] if hdr.IsLongHeader { - if protocol.ByteCount(len(packetData)) < hdr.PayloadLen { - return fmt.Errorf("packet payload (%d bytes) is smaller than the expected payload length (%d bytes)", len(packetData), hdr.PayloadLen) + if hdr.Length < protocol.ByteCount(hdr.PacketNumberLen) { + return fmt.Errorf("packet length (%d bytes) shorter than packet number (%d bytes)", hdr.Length, hdr.PacketNumberLen) } - packetData = packetData[:int(hdr.PayloadLen)] + if protocol.ByteCount(len(packetData))+protocol.ByteCount(hdr.PacketNumberLen) < hdr.Length { + return fmt.Errorf("packet length (%d bytes) is smaller than the expected length (%d bytes)", len(packetData)+int(hdr.PacketNumberLen), hdr.Length) + } + packetData = packetData[:int(hdr.Length)-int(hdr.PacketNumberLen)] // TODO(#1312): implement parsing of compound packets } diff --git a/vendor/github.com/lucas-clemente/quic-go/packet_packer.go b/vendor/github.com/lucas-clemente/quic-go/packet_packer.go index 4260aa22..e1510341 100644 --- a/vendor/github.com/lucas-clemente/quic-go/packet_packer.go +++ b/vendor/github.com/lucas-clemente/quic-go/packet_packer.go @@ -409,9 +409,9 @@ func (p *packetPacker) getHeader(encLevel protocol.EncryptionLevel) *wire.Header if encLevel != protocol.Encryption1RTT { header.IsLongHeader = true header.SrcConnectionID = p.srcConnID - // Set the payload len to maximum size. + // Set the length to the maximum packet size. // Since it is encoded as a varint, this guarantees us that the header will end up at most as big as GetLength() returns. - header.PayloadLen = p.maxPacketSize + header.Length = p.maxPacketSize switch encLevel { case protocol.EncryptionInitial: header.Type = protocol.PacketTypeInitial @@ -433,20 +433,20 @@ func (p *packetPacker) writeAndSealPacket( addPadding := p.perspective == protocol.PerspectiveClient && header.Type == protocol.PacketTypeInitial && !p.hasSentPacket - // the payload length is only needed for Long Headers + // the length is only needed for Long Headers if header.IsLongHeader { if p.perspective == protocol.PerspectiveClient && header.Type == protocol.PacketTypeInitial { header.Token = p.token } if addPadding { headerLen := header.GetLength(p.version) - header.PayloadLen = protocol.ByteCount(protocol.MinInitialPacketSize) - headerLen + header.Length = protocol.ByteCount(header.PacketNumberLen) + protocol.MinInitialPacketSize - headerLen } else { - payloadLen := protocol.ByteCount(sealer.Overhead()) + length := protocol.ByteCount(sealer.Overhead()) + protocol.ByteCount(header.PacketNumberLen) for _, frame := range frames { - payloadLen += frame.Length(p.version) + length += frame.Length(p.version) } - header.PayloadLen = payloadLen + header.Length = length } }