peer_protocol: Add a test for receiving overlong piece data
The chunk buffer pool decides the upper bound on chunk data len.
This commit is contained in:
parent
d4d8f78906
commit
01380adac3
|
@ -73,3 +73,21 @@ func TestDecodeShortPieceEOF(t *testing.T) {
|
|||
assert.Len(t, m.Piece, 1)
|
||||
assert.Equal(t, io.EOF, d.Decode(&m))
|
||||
}
|
||||
|
||||
func TestDecodeOverlongPiece(t *testing.T) {
|
||||
r, w := io.Pipe()
|
||||
go func() {
|
||||
w.Write(Message{Type: Piece, Piece: make([]byte, 3)}.MustMarshalBinary())
|
||||
w.Close()
|
||||
}()
|
||||
d := Decoder{
|
||||
R: bufio.NewReader(r),
|
||||
MaxLength: 1 << 15,
|
||||
Pool: &sync.Pool{New: func() interface{} {
|
||||
b := make([]byte, 2)
|
||||
return &b
|
||||
}},
|
||||
}
|
||||
var m Message
|
||||
require.EqualError(t, d.Decode(&m), "piece data longer than expected")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue