mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 23:33:37 +00:00
network: use MaxHeadersAllowed to restrict GetBlockByIndex
This commit is contained in:
parent
737ba700e9
commit
0b856033b0
2 changed files with 2 additions and 5 deletions
|
@ -6,9 +6,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
)
|
)
|
||||||
|
|
||||||
// maximum number of blocks to query about
|
|
||||||
const maxBlockCount = 500
|
|
||||||
|
|
||||||
// GetBlockByIndex payload
|
// GetBlockByIndex payload
|
||||||
type GetBlockByIndex struct {
|
type GetBlockByIndex struct {
|
||||||
IndexStart uint32
|
IndexStart uint32
|
||||||
|
@ -27,7 +24,7 @@ func NewGetBlockByIndex(indexStart uint32, count uint16) *GetBlockByIndex {
|
||||||
func (d *GetBlockByIndex) DecodeBinary(br *io.BinReader) {
|
func (d *GetBlockByIndex) DecodeBinary(br *io.BinReader) {
|
||||||
d.IndexStart = br.ReadU32LE()
|
d.IndexStart = br.ReadU32LE()
|
||||||
d.Count = br.ReadU16LE()
|
d.Count = br.ReadU16LE()
|
||||||
if d.Count == 0 || d.Count > maxBlockCount {
|
if d.Count == 0 || d.Count > MaxHeadersAllowed {
|
||||||
br.Err = errors.New("invalid block count")
|
br.Err = errors.New("invalid block count")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ func TestGetBlockDataEncodeDecode(t *testing.T) {
|
||||||
require.Error(t, testserdes.DecodeBinary(data, new(GetBlockByIndex)))
|
require.Error(t, testserdes.DecodeBinary(data, new(GetBlockByIndex)))
|
||||||
|
|
||||||
// invalid block count
|
// invalid block count
|
||||||
d = NewGetBlockByIndex(5, maxBlockCount+1)
|
d = NewGetBlockByIndex(5, MaxHeadersAllowed+1)
|
||||||
data, err = testserdes.EncodeBinary(d)
|
data, err = testserdes.EncodeBinary(d)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Error(t, testserdes.DecodeBinary(data, new(GetBlockByIndex)))
|
require.Error(t, testserdes.DecodeBinary(data, new(GetBlockByIndex)))
|
||||||
|
|
Loading…
Reference in a new issue