From 913f6df80d4eac2c18980e4b0f10d746427e2ecf Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Thu, 23 Jan 2020 13:56:39 +1100 Subject: [PATCH] Use CopyN to ensure early io.EOF isn't ignored when hashing pieces --- torrent.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/torrent.go b/torrent.go index f7f518f8..0f4a6810 100644 --- a/torrent.go +++ b/torrent.go @@ -769,7 +769,8 @@ func (t *Torrent) hashPiece(piece pieceIndex) (ret metainfo.Hash, copyErr error) p.waitNoPendingWrites() ip := t.info.Piece(int(piece)) pl := ip.Length() - _, copyErr = io.Copy(hash, io.NewSectionReader(t.pieces[piece].Storage(), 0, pl)) + _, copyErr = io.CopyN( // Return no error iff pl bytes are copied. + hash, io.NewSectionReader(t.pieces[piece].Storage(), 0, pl), pl) missinggo.CopyExact(&ret, hash.Sum(nil)) return } -- 2.48.1