]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix panic in connection.iterPendingPieces when the info isn't available
authorMatt Joiner <anacrolix@gmail.com>
Thu, 28 Jun 2018 01:12:49 +0000 (11:12 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 28 Jun 2018 01:12:49 +0000 (11:12 +1000)
Triggered by connection.iterUnbiasedPieceRequestOrder calling Torrent.numPieces. We shouldn't be iterating pieces when there's no info anyway, so don't yield any. Mentioned in https://github.com/anacrolix/torrent/issues/253#issuecomment-400350386.

connection.go

index 63a0da6b47c4afe771aed58f011f6a51ff20b6eb..0c3bc1c4898de120ddd9346109ecd3fd16c0a46a 100644 (file)
@@ -739,6 +739,9 @@ func (cn *connection) shouldRequestWithoutBias() bool {
 }
 
 func (cn *connection) iterPendingPieces(f func(int) bool) bool {
+       if !cn.t.haveInfo() {
+               return false
+       }
        if cn.t.requestStrategy == 3 {
                return cn.iterUnbiasedPieceRequestOrder(f)
        }