forked from quic-go/quic-go
throw a MissingPayload error when unpacking packets with no frames
fixes #175
This commit is contained in:
@@ -37,6 +37,10 @@ func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *publicHeader, r
|
|||||||
}
|
}
|
||||||
entropyBit := privateFlag&0x01 > 0
|
entropyBit := privateFlag&0x01 > 0
|
||||||
|
|
||||||
|
if r.Len() == 0 {
|
||||||
|
return nil, qerr.MissingPayload
|
||||||
|
}
|
||||||
|
|
||||||
fs := make([]frames.Frame, 0, 1)
|
fs := make([]frames.Frame, 0, 1)
|
||||||
|
|
||||||
// Read all frames in the packet
|
// Read all frames in the packet
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/lucas-clemente/quic-go/crypto"
|
"github.com/lucas-clemente/quic-go/crypto"
|
||||||
"github.com/lucas-clemente/quic-go/frames"
|
"github.com/lucas-clemente/quic-go/frames"
|
||||||
"github.com/lucas-clemente/quic-go/protocol"
|
"github.com/lucas-clemente/quic-go/protocol"
|
||||||
|
"github.com/lucas-clemente/quic-go/qerr"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
@@ -37,12 +38,17 @@ var _ = Describe("Packet unpacker", func() {
|
|||||||
r = bytes.NewReader(aead.Seal(0, hdrBin, append([]byte{0x01}, data...)))
|
r = bytes.NewReader(aead.Seal(0, hdrBin, append([]byte{0x01}, data...)))
|
||||||
}
|
}
|
||||||
|
|
||||||
It("unpacks empty packets", func() {
|
It("returns an error for empty packets that don't have a private flag", func() {
|
||||||
|
// don't use setReader here, since it adds a private flag
|
||||||
|
r = bytes.NewReader(aead.Seal(0, hdrBin, []byte{}))
|
||||||
|
_, err := unpacker.Unpack(hdrBin, hdr, r)
|
||||||
|
Expect(err).To(MatchError(qerr.MissingPayload))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("returns an error for empty packets that have a private flag", func() {
|
||||||
setReader(nil)
|
setReader(nil)
|
||||||
packet, err := unpacker.Unpack(hdrBin, hdr, r)
|
_, err := unpacker.Unpack(hdrBin, hdr, r)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).To(MatchError(qerr.MissingPayload))
|
||||||
Expect(packet.entropyBit).To(BeTrue())
|
|
||||||
Expect(packet.frames).To(BeEmpty())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("unpacks stream frames", func() {
|
It("unpacks stream frames", func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user