network: restrict flags size in MerkleBlockPayload

This commit is contained in:
Anna Shaleva 2020-10-02 19:30:29 +03:00
parent 560e470484
commit 6cff35c927
2 changed files with 15 additions and 1 deletions

View file

@ -26,7 +26,7 @@ func (m *MerkleBlock) DecodeBinary(br *io.BinReader) {
} }
m.TxCount = txCount m.TxCount = txCount
br.ReadArray(&m.Hashes, m.TxCount) br.ReadArray(&m.Hashes, m.TxCount)
m.Flags = br.ReadVarBytes() m.Flags = br.ReadVarBytes((txCount + 7) / 8)
} }
// EncodeBinary implements Serializable interface. // EncodeBinary implements Serializable interface.

View file

@ -54,4 +54,18 @@ func TestMerkleBlock_EncodeDecodeBinary(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.True(t, errors.Is(block.ErrMaxContentsPerBlock, testserdes.DecodeBinary(data, new(MerkleBlock)))) 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)))
})
} }