From c18e0abe526d6926d18edb0250fbb32a2a0269f7 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 19 Oct 2021 13:13:23 +1100 Subject: [PATCH] Fix incomplete Integer.Read Possibly on read buffer boundaries, this would have caused errant io.ErrUnexpectedEOF. (cherry picked from commit 22569449dad48e1c5cdeac171625585f8ca976c9) --- peer_protocol/int.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 } -- 2.48.1