diff --git a/blockchain/reactor.go b/blockchain/reactor.go index 64f4445a9..33dfdd288 100644 --- a/blockchain/reactor.go +++ b/blockchain/reactor.go @@ -30,7 +30,7 @@ const ( // NOTE: keep up to date with bcBlockResponseMessage bcBlockResponseMessagePrefixSize = 4 bcBlockResponseMessageFieldKeySize = 1 - maxMessageSize = types.MaxBlockSizeBytes + + maxMsgSize = types.MaxBlockSizeBytes + bcBlockResponseMessagePrefixSize + bcBlockResponseMessageFieldKeySize ) @@ -133,7 +133,7 @@ func (bcR *BlockchainReactor) GetChannels() []*p2p.ChannelDescriptor { Priority: 10, SendQueueCapacity: 1000, RecvBufferCapacity: 50 * 4096, - RecvMessageCapacity: maxMessageSize, + RecvMessageCapacity: maxMsgSize, }, } } @@ -345,6 +345,10 @@ func RegisterBlockchainMessages(cdc *amino.Codec) { // DecodeMessage decodes BlockchainMessage. // TODO: ensure that bz is completely read. func DecodeMessage(bz []byte) (msg BlockchainMessage, err error) { + if len(bz) > maxMsgSize { + return msg, fmt.Errorf("Msg exceeds max size (%d > %d)", + len(bz), maxMsgSize) + } err = cdc.UnmarshalBinaryBare(bz, &msg) if err != nil { err = cmn.ErrorWrap(err, "DecodeMessage() had bytes left over") diff --git a/consensus/reactor.go b/consensus/reactor.go index 2c8d4d85a..8f341184e 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -25,7 +25,7 @@ const ( VoteChannel = byte(0x22) VoteSetBitsChannel = byte(0x23) - maxConsensusMessageSize = 1048576 // 1MB; NOTE/TODO: keep in sync with types.PartSet sizes. + maxMsgSize = 1048576 // 1MB; NOTE/TODO: keep in sync with types.PartSet sizes. blocksToContributeToBecomeGoodPeer = 10000 ) @@ -112,28 +112,28 @@ func (conR *ConsensusReactor) GetChannels() []*p2p.ChannelDescriptor { ID: StateChannel, Priority: 5, SendQueueCapacity: 100, - RecvMessageCapacity: maxConsensusMessageSize, + RecvMessageCapacity: maxMsgSize, }, { ID: DataChannel, // maybe split between gossiping current block and catchup stuff Priority: 10, // once we gossip the whole block there's nothing left to send until next height or round SendQueueCapacity: 100, RecvBufferCapacity: 50 * 4096, - RecvMessageCapacity: maxConsensusMessageSize, + RecvMessageCapacity: maxMsgSize, }, { ID: VoteChannel, Priority: 5, SendQueueCapacity: 100, RecvBufferCapacity: 100 * 100, - RecvMessageCapacity: maxConsensusMessageSize, + RecvMessageCapacity: maxMsgSize, }, { ID: VoteSetBitsChannel, Priority: 1, SendQueueCapacity: 2, RecvBufferCapacity: 1024, - RecvMessageCapacity: maxConsensusMessageSize, + RecvMessageCapacity: maxMsgSize, }, } } @@ -1314,6 +1314,10 @@ func RegisterConsensusMessages(cdc *amino.Codec) { // DecodeMessage decodes the given bytes into a ConsensusMessage. func DecodeMessage(bz []byte) (msg ConsensusMessage, err error) { + if len(bz) > maxMsgSize { + return msg, fmt.Errorf("Msg exceeds max size (%d > %d)", + len(bz), maxMsgSize) + } err = cdc.UnmarshalBinaryBare(bz, &msg) return } diff --git a/evidence/reactor.go b/evidence/reactor.go index 27cbdbf31..a6aa66b1f 100644 --- a/evidence/reactor.go +++ b/evidence/reactor.go @@ -2,11 +2,12 @@ package evidence import ( "fmt" - "github.com/tendermint/go-amino" - "github.com/tendermint/tmlibs/log" "reflect" "time" + "github.com/tendermint/go-amino" + "github.com/tendermint/tmlibs/log" + "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/types" ) @@ -14,7 +15,7 @@ import ( const ( EvidenceChannel = byte(0x38) - maxEvidenceMessageSize = 1048576 // 1MB TODO make it configurable + maxMsgSize = 1048576 // 1MB TODO make it configurable broadcastEvidenceIntervalS = 60 // broadcast uncommitted evidence this often ) @@ -146,6 +147,10 @@ func RegisterEvidenceMessages(cdc *amino.Codec) { // DecodeMessage decodes a byte-array into a EvidenceMessage. func DecodeMessage(bz []byte) (msg EvidenceMessage, err error) { + if len(bz) > maxMsgSize { + return msg, fmt.Errorf("Msg exceeds max size (%d > %d)", + len(bz), maxMsgSize) + } err = cdc.UnmarshalBinaryBare(bz, &msg) return } diff --git a/mempool/reactor.go b/mempool/reactor.go index acd693e42..54a3c32fe 100644 --- a/mempool/reactor.go +++ b/mempool/reactor.go @@ -18,7 +18,7 @@ import ( const ( MempoolChannel = byte(0x30) - maxMempoolMessageSize = 1048576 // 1MB TODO make it configurable + maxMsgSize = 1048576 // 1MB TODO make it configurable peerCatchupSleepIntervalMS = 100 // If peer is behind, sleep this amount ) @@ -167,6 +167,10 @@ func RegisterMempoolMessages(cdc *amino.Codec) { // DecodeMessage decodes a byte-array into a MempoolMessage. func DecodeMessage(bz []byte) (msg MempoolMessage, err error) { + if len(bz) > maxMsgSize { + return msg, fmt.Errorf("Msg exceeds max size (%d > %d)", + len(bz), maxMsgSize) + } err = cdc.UnmarshalBinaryBare(bz, &msg) return } diff --git a/p2p/pex/pex_reactor.go b/p2p/pex/pex_reactor.go index db4bb9f08..00144c35f 100644 --- a/p2p/pex/pex_reactor.go +++ b/p2p/pex/pex_reactor.go @@ -21,7 +21,7 @@ const ( // PexChannel is a channel for PEX messages PexChannel = byte(0x00) - maxPexMessageSize = 1048576 // 1MB + maxMsgSize = 1048576 // 1MB // ensure we have enough peers defaultEnsurePeersPeriod = 30 * time.Second @@ -616,6 +616,10 @@ func RegisterPexMessage(cdc *amino.Codec) { // DecodeMessage implements interface registered above. func DecodeMessage(bz []byte) (msg PexMessage, err error) { + if len(bz) > maxMsgSize { + return msg, fmt.Errorf("Msg exceeds max size (%d > %d)", + len(bz), maxMsgSize) + } err = cdc.UnmarshalBinary(bz, &msg) return } diff --git a/types/priv_validator.go b/types/priv_validator.go index ecba4456f..8759d3f99 100644 --- a/types/priv_validator.go +++ b/types/priv_validator.go @@ -92,5 +92,4 @@ func (pv *MockPV) String() string { func (pv *MockPV) DisableChecks() { // Currently this does nothing, // as MockPV has no safety checks at all. - return }