allow empty STREAM frames at arbitrary offsets

This commit is contained in:
Marten Seemann
2018-05-11 11:08:08 +09:00
parent 240896a4dd
commit 5f5bb1f700
5 changed files with 10 additions and 29 deletions

View File

@@ -76,10 +76,6 @@ func parseStreamFrame(r *bytes.Reader, version protocol.VersionNumber) (*StreamF
if frame.Offset+frame.DataLen() > protocol.MaxByteCount {
return nil, qerr.Error(qerr.InvalidStreamData, "data overflows maximum offset")
}
// empty frames are only allowed if they have offset 0 or the FIN bit set
if frame.DataLen() == 0 && !frame.FinBit && frame.Offset != 0 {
return nil, qerr.EmptyStreamFrameNoFin
}
return frame, nil
}

View File

@@ -56,27 +56,19 @@ var _ = Describe("STREAM frame (for IETF QUIC)", func() {
Expect(r.Len()).To(BeZero())
})
It("allows empty frames at offset 0", func() {
data := []byte{0x10}
data = append(data, encodeVarInt(0x1337)...) // stream ID
It("allows empty frames", func() {
data := []byte{0x10 ^ 0x4}
data = append(data, encodeVarInt(0x1337)...) // stream ID
data = append(data, encodeVarInt(0x12345)...) // offset
r := bytes.NewReader(data)
f, err := parseStreamFrame(r, versionIETFFrames)
Expect(err).ToNot(HaveOccurred())
Expect(f.StreamID).To(Equal(protocol.StreamID(0x1337)))
Expect(f.Offset).To(Equal(protocol.ByteCount(0x12345)))
Expect(f.Data).To(BeEmpty())
Expect(f.Offset).To(BeZero())
Expect(f.FinBit).To(BeFalse())
})
It("rejects empty frames than don't have the FIN bit set", func() {
data := []byte{0x10 ^ 0x4}
data = append(data, encodeVarInt(0x1337)...) // stream ID
data = append(data, encodeVarInt(0xdecafbad)...) // offset
r := bytes.NewReader(data)
_, err := parseStreamFrame(r, versionIETFFrames)
Expect(err).To(MatchError(qerr.EmptyStreamFrameNoFin))
})
It("rejects frames that overflow the maximum offset", func() {
data := []byte{0x10 ^ 0x4}
data = append(data, encodeVarInt(0x12345)...) // stream ID