lnwire: use ReadFull instead of Read when parsing feature vectors

This commit fixes a bug lingering in the decoding of the feature
vectors which was masked by the prior method of reading the _entire_
message from the stream before parsing it. The issue was that
performing a zero-byte Read on an io.Reader that’s purely streaming
will result in an indefinite block. We fix this bug by properly using
io.ReadFull in this context.
This commit is contained in:
Olaoluwa Osuntokun 2017-04-19 16:07:11 -07:00
parent 9324a503c9
commit 587300aa80
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -136,14 +136,14 @@ func NewFeatureVectorFromReader(r io.Reader) (*FeatureVector, error) {
// Read the length of the feature vector.
var l [2]byte
if _, err := r.Read(l[:]); err != nil {
if _, err := io.ReadFull(r, l[:]); err != nil {
return nil, err
}
length := binary.BigEndian.Uint16(l[:])
// Read the feature vector data.
data := make([]byte, length)
if _, err := r.Read(data); err != nil {
if _, err := io.ReadFull(r, data[:]); err != nil {
return nil, err
}