client.go | 15 +++++++++++---- diff --git a/client.go b/client.go index 2a20b263385c0b802bd7b26e3708f45b8b777581..86f908818c1fe354900964d6faae75997a1c429f 100644 --- a/client.go +++ b/client.go @@ -161,10 +161,14 @@ err = io.EOF return } piece := t.Pieces[index] - pieceOff := pp.Integer(off % int64(t.PieceLength(0))) - high := int(t.PieceLength(index) - pieceOff) - if high < len(p) { - p = p[:high] + pieceOff := pp.Integer(off % int64(t.UsualPieceSize())) + pieceLeft := int(t.PieceLength(index) - pieceOff) + if pieceLeft <= 0 { + err = io.EOF + return + } + if len(p) > pieceLeft { + p = p[:pieceLeft] } for cs, _ := range piece.PendingChunkSpecs { chunkOff := int64(pieceOff) - int64(cs.Begin) @@ -180,6 +184,9 @@ // pending chunk caps available data if chunkOff < 0 && int64(len(p)) > -chunkOff { p = p[:-chunkOff] } + } + if len(p) == 0 { + panic(len(p)) } return t.Data.ReadAt(p, off) }