From 00a4e9bc1180cb8756ca5ac8689780b7e7261412 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Fri, 22 Aug 2014 03:42:00 +1000 Subject: [PATCH] Fix crash in metadata requests beyond available info bytes --- torrent.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/torrent.go b/torrent.go index 7257bb30..178f29ae 100644 --- a/torrent.go +++ b/torrent.go @@ -91,7 +91,11 @@ func (t *torrent) MetadataPieceCount() int { } func (t *torrent) HaveMetadataPiece(piece int) bool { - return t.haveInfo() || t.metadataHave[piece] + if t.haveInfo() { + return (1<<14)*piece < len(t.MetaData) + } else { + return t.metadataHave[piece] + } } func (t *torrent) metadataSizeKnown() bool {