From 7b924822c712e58d85d920828d821a9b5aafc242 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Thu, 28 Jun 2018 11:12:49 +1000 Subject: [PATCH] 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. --- connection.go | 3 +++ 1 file changed, 3 insertions(+) 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) } -- 2.48.1