From f535cc40de278f6edfd8b40ad06d6aeed8c1620c Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 4 Aug 2017 19:34:30 +0700 Subject: [PATCH] use io.ReadFull instead of Read to read into known length slices --- frames/stream_frame.go | 7 ++----- public_header.go | 5 ++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/frames/stream_frame.go b/frames/stream_frame.go index 7dd622356..f4a7bf739 100644 --- a/frames/stream_frame.go +++ b/frames/stream_frame.go @@ -3,6 +3,7 @@ package frames import ( "bytes" "errors" + "io" "github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/protocol" @@ -70,11 +71,7 @@ func ParseStreamFrame(r *bytes.Reader) (*StreamFrame, error) { } if dataLen != 0 { frame.Data = make([]byte, dataLen) - n, err := r.Read(frame.Data) - if n != int(dataLen) { - return nil, errors.New("BUG: StreamFrame could not read dataLen bytes") - } - if err != nil { + if _, err := io.ReadFull(r, frame.Data); err != nil { return nil, err } } diff --git a/public_header.go b/public_header.go index 59ddc6cb4..4af66ab16 100644 --- a/public_header.go +++ b/public_header.go @@ -3,6 +3,7 @@ package quic import ( "bytes" "errors" + "io" "github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/protocol" @@ -166,9 +167,7 @@ func ParsePublicHeader(b *bytes.Reader, packetSentBy protocol.Perspective) (*Pub // see https://github.com/lucas-clemente/quic-go/issues/232 if !header.VersionFlag && !header.ResetFlag { header.DiversificationNonce = make([]byte, 32) - // this Read can never return an EOF for a valid packet, since the diversification nonce is followed by the packet number - _, err = b.Read(header.DiversificationNonce) - if err != nil { + if _, err := io.ReadFull(b, header.DiversificationNonce); err != nil { return nil, err } }