From: Matt Joiner Date: Thu, 28 Jun 2018 01:12:49 +0000 (+1000) Subject: Fix panic in connection.iterPendingPieces when the info isn't available X-Git-Tag: v1.0.0~112 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=7b924822c712e58d85d920828d821a9b5aafc242;p=btrtrc.git Fix panic in connection.iterPendingPieces when the info isn't available 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. --- diff --git a/connection.go b/connection.go index 63a0da6b..0c3bc1c4 100644 --- a/connection.go +++ b/connection.go @@ -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) }