forked from TrueCloudLab/neoneo-go
network: restrict flags size in MerkleBlockPayload
This commit is contained in:
parent
560e470484
commit
6cff35c927
2 changed files with 15 additions and 1 deletions
|
@ -26,7 +26,7 @@ func (m *MerkleBlock) DecodeBinary(br *io.BinReader) {
|
|||
}
|
||||
m.TxCount = txCount
|
||||
br.ReadArray(&m.Hashes, m.TxCount)
|
||||
m.Flags = br.ReadVarBytes()
|
||||
m.Flags = br.ReadVarBytes((txCount + 7) / 8)
|
||||
}
|
||||
|
||||
// EncodeBinary implements Serializable interface.
|
||||
|
|
|
@ -54,4 +54,18 @@ func TestMerkleBlock_EncodeDecodeBinary(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.True(t, errors.Is(block.ErrMaxContentsPerBlock, testserdes.DecodeBinary(data, new(MerkleBlock))))
|
||||
})
|
||||
|
||||
t.Run("bad flags size", func(t *testing.T) {
|
||||
b := newDumbBlock()
|
||||
_ = b.Hash()
|
||||
expected := &MerkleBlock{
|
||||
Base: b,
|
||||
TxCount: 0,
|
||||
Hashes: []util.Uint256{},
|
||||
Flags: []byte{1, 2, 3, 4, 5},
|
||||
}
|
||||
data, err := testserdes.EncodeBinary(expected)
|
||||
require.NoError(t, err)
|
||||
require.Error(t, testserdes.DecodeBinary(data, new(MerkleBlock)))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue