Add some checks to TorrentReadAt for 0 byte reads
This commit is contained in:
parent
6dce2cbf76
commit
8f065e473f
15
client.go
15
client.go
@ -161,10 +161,14 @@ func (cl *Client) TorrentReadAt(ih InfoHash, off int64, p []byte) (n int, err er
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
piece := t.Pieces[index]
|
piece := t.Pieces[index]
|
||||||
pieceOff := pp.Integer(off % int64(t.PieceLength(0)))
|
pieceOff := pp.Integer(off % int64(t.UsualPieceSize()))
|
||||||
high := int(t.PieceLength(index) - pieceOff)
|
pieceLeft := int(t.PieceLength(index) - pieceOff)
|
||||||
if high < len(p) {
|
if pieceLeft <= 0 {
|
||||||
p = p[:high]
|
err = io.EOF
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(p) > pieceLeft {
|
||||||
|
p = p[:pieceLeft]
|
||||||
}
|
}
|
||||||
for cs, _ := range piece.PendingChunkSpecs {
|
for cs, _ := range piece.PendingChunkSpecs {
|
||||||
chunkOff := int64(pieceOff) - int64(cs.Begin)
|
chunkOff := int64(pieceOff) - int64(cs.Begin)
|
||||||
@ -181,6 +185,9 @@ func (cl *Client) TorrentReadAt(ih InfoHash, off int64, p []byte) (n int, err er
|
|||||||
p = p[:-chunkOff]
|
p = p[:-chunkOff]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(p) == 0 {
|
||||||
|
panic(len(p))
|
||||||
|
}
|
||||||
return t.Data.ReadAt(p, off)
|
return t.Data.ReadAt(p, off)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user