From: Matt Joiner Date: Thu, 23 Jan 2020 02:56:39 +0000 (+1100) Subject: Use CopyN to ensure early io.EOF isn't ignored when hashing pieces X-Git-Tag: v1.12.0~1 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=913f6df80d4eac2c18980e4b0f10d746427e2ecf;p=btrtrc.git Use CopyN to ensure early io.EOF isn't ignored when hashing pieces --- 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 }