]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Use CopyN to ensure early io.EOF isn't ignored when hashing pieces
authorMatt Joiner <anacrolix@gmail.com>
Thu, 23 Jan 2020 02:56:39 +0000 (13:56 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 23 Jan 2020 02:56:39 +0000 (13:56 +1100)
torrent.go

index f7f518f8b75f261c34dee1e857db0857c45cfcd4..0f4a681024302451c2e7b247ea49324eb014f9f8 100644 (file)
@@ -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
 }