diff --git a/pkg/network/message.go b/pkg/network/message.go index efa58ad29..e710a0039 100644 --- a/pkg/network/message.go +++ b/pkg/network/message.go @@ -159,7 +159,7 @@ func (m *Message) decodePayload() error { case CMDTX: p = &transaction.Transaction{Network: m.Network} case CMDMerkleBlock: - p = &payload.MerkleBlock{} + p = &payload.MerkleBlock{Network: m.Network} case CMDPing, CMDPong: p = &payload.Ping{} case CMDNotFound: diff --git a/pkg/network/payload/merkleblock.go b/pkg/network/payload/merkleblock.go index 9867e4ab0..b53499085 100644 --- a/pkg/network/payload/merkleblock.go +++ b/pkg/network/payload/merkleblock.go @@ -1,6 +1,9 @@ package payload import ( + "errors" + + "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/util" @@ -9,6 +12,7 @@ import ( // MerkleBlock represents a merkle block packet payload. type MerkleBlock struct { *block.Base + Network netmode.Magic TxCount int Hashes []util.Uint256 Flags []byte @@ -16,7 +20,7 @@ type MerkleBlock struct { // DecodeBinary implements Serializable interface. func (m *MerkleBlock) DecodeBinary(br *io.BinReader) { - m.Base = &block.Base{} + m.Base = &block.Base{Network: m.Network} m.Base.DecodeBinary(br) txCount := int(br.ReadVarUint()) @@ -26,6 +30,9 @@ func (m *MerkleBlock) DecodeBinary(br *io.BinReader) { } m.TxCount = txCount br.ReadArray(&m.Hashes, m.TxCount) + if txCount != len(m.Hashes) { + br.Err = errors.New("invalid tx count") + } m.Flags = br.ReadVarBytes((txCount + 7) / 8) }