From 587300aa80cf546c7fd0023434169dc488c9ae32 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 19 Apr 2017 16:07:11 -0700 Subject: [PATCH] lnwire: use ReadFull instead of Read when parsing feature vectors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- lnwire/features.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lnwire/features.go b/lnwire/features.go index b55ab88b..e2be0426 100644 --- a/lnwire/features.go +++ b/lnwire/features.go @@ -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 }