forked from quic-go/quic-go
use io.ReadFull instead of Read to read into known length slices
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user