client.go | 6 +++++- diff --git a/client.go b/client.go index efa41e2c050922c71aebe24dc2840c3f67726394..9469096fca4752db4d6f37d4a6029d392d054980 100644 --- a/client.go +++ b/client.go @@ -1249,7 +1249,7 @@ t.connPendPiece(c, i) } } -func (me *Client) peerGotPiece(t *torrent, c *connection, piece int) { +func (me *Client) peerGotPiece(t *torrent, c *connection, piece int) error { if !c.peerHasAll { if t.haveInfo() { if c.PeerPieces == nil { @@ -1260,12 +1260,16 @@ for piece >= len(c.PeerPieces) { c.PeerPieces = append(c.PeerPieces, false) } } + if piece >= len(c.PeerPieces) { + return errors.New("peer got out of range piece index") + } c.PeerPieces[piece] = true } if t.wantPiece(piece) { t.connPendPiece(c, piece) me.replenishConnRequests(t, c) } + return nil } func (me *Client) peerUnchoked(torrent *torrent, conn *connection) {