From: Matt Joiner Date: Tue, 19 Oct 2021 02:13:23 +0000 (+1100) Subject: Fix incomplete Integer.Read X-Git-Tag: v1.34.0~3 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=c18e0abe526d6926d18edb0250fbb32a2a0269f7;p=btrtrc.git Fix incomplete Integer.Read Possibly on read buffer boundaries, this would have caused errant io.ErrUnexpectedEOF. (cherry picked from commit 22569449dad48e1c5cdeac171625585f8ca976c9) --- diff --git a/peer_protocol/int.go b/peer_protocol/int.go index 80fb6624..13bd1ca9 100644 --- a/peer_protocol/int.go +++ b/peer_protocol/int.go @@ -19,12 +19,12 @@ func (i *Integer) UnmarshalBinary(b []byte) error { func (i *Integer) Read(r io.Reader) error { var b [4]byte - n, err := r.Read(b[:]) - if n == 4 { - return i.UnmarshalBinary(b[:]) - } + n, err := io.ReadFull(r, b[:]) if err == nil { - return io.ErrUnexpectedEOF + if n != 4 { + panic(n) + } + return i.UnmarshalBinary(b[:]) } return err }