torrent.go | 3 ++- diff --git a/torrent.go b/torrent.go index f7f518f8b75f261c34dee1e857db0857c45cfcd4..0f4a681024302451c2e7b247ea49324eb014f9f8 100644 --- a/torrent.go +++ b/torrent.go @@ -769,7 +769,8 @@ p := t.piece(piece) 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 }