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:
parent
9324a503c9
commit
587300aa80
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user