forked from quic-go/quic-go
return error empty StreamFrames that don't have the FinBit set
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/qerr"
|
||||
"github.com/lucas-clemente/quic-go/utils"
|
||||
)
|
||||
|
||||
@@ -74,6 +75,10 @@ func ParseStreamFrame(r *bytes.Reader) (*StreamFrame, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if !frame.FinBit && len(frame.Data) == 0 {
|
||||
return nil, qerr.EmptyStreamFrameNoFin
|
||||
}
|
||||
|
||||
return frame, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/qerr"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
@@ -31,6 +32,21 @@ var _ = Describe("StreamFrame", func() {
|
||||
Expect(frame.DataLenPresent).To(BeFalse())
|
||||
Expect(frame.Data).To(Equal([]byte("foobar")))
|
||||
})
|
||||
|
||||
It("accepts empty frame with finbit set", func() {
|
||||
b := bytes.NewReader([]byte{0x80 ^ 0x40 ^ 0x20, 0x1, 0, 0})
|
||||
frame, err := ParseStreamFrame(b)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame.FinBit).To(BeTrue())
|
||||
Expect(frame.DataLenPresent).To(BeTrue())
|
||||
Expect(frame.Data).To(HaveLen(0))
|
||||
})
|
||||
|
||||
It("errors on empty stream frames that don't have the FinBit set", func() {
|
||||
b := bytes.NewReader([]byte{0x80 ^ 0x20, 0x1, 0, 0})
|
||||
_, err := ParseStreamFrame(b)
|
||||
Expect(err).To(MatchError(qerr.EmptyStreamFrameNoFin))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when writing", func() {
|
||||
|
||||
Reference in New Issue
Block a user