Browse Source

check max msg size in DecodeMessage

pull/1432/head
Ethan Buchman 7 years ago
parent
commit
1a1e4e767b
6 changed files with 33 additions and 13 deletions
  1. +6
    -2
      blockchain/reactor.go
  2. +9
    -5
      consensus/reactor.go
  3. +8
    -3
      evidence/reactor.go
  4. +5
    -1
      mempool/reactor.go
  5. +5
    -1
      p2p/pex/pex_reactor.go
  6. +0
    -1
      types/priv_validator.go

+ 6
- 2
blockchain/reactor.go View File

@ -30,7 +30,7 @@ const (
// NOTE: keep up to date with bcBlockResponseMessage // NOTE: keep up to date with bcBlockResponseMessage
bcBlockResponseMessagePrefixSize = 4 bcBlockResponseMessagePrefixSize = 4
bcBlockResponseMessageFieldKeySize = 1 bcBlockResponseMessageFieldKeySize = 1
maxMessageSize = types.MaxBlockSizeBytes +
maxMsgSize = types.MaxBlockSizeBytes +
bcBlockResponseMessagePrefixSize + bcBlockResponseMessagePrefixSize +
bcBlockResponseMessageFieldKeySize bcBlockResponseMessageFieldKeySize
) )
@ -133,7 +133,7 @@ func (bcR *BlockchainReactor) GetChannels() []*p2p.ChannelDescriptor {
Priority: 10, Priority: 10,
SendQueueCapacity: 1000, SendQueueCapacity: 1000,
RecvBufferCapacity: 50 * 4096, RecvBufferCapacity: 50 * 4096,
RecvMessageCapacity: maxMessageSize,
RecvMessageCapacity: maxMsgSize,
}, },
} }
} }
@ -345,6 +345,10 @@ func RegisterBlockchainMessages(cdc *amino.Codec) {
// DecodeMessage decodes BlockchainMessage. // DecodeMessage decodes BlockchainMessage.
// TODO: ensure that bz is completely read. // TODO: ensure that bz is completely read.
func DecodeMessage(bz []byte) (msg BlockchainMessage, err error) { 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) err = cdc.UnmarshalBinaryBare(bz, &msg)
if err != nil { if err != nil {
err = cmn.ErrorWrap(err, "DecodeMessage() had bytes left over") err = cmn.ErrorWrap(err, "DecodeMessage() had bytes left over")


+ 9
- 5
consensus/reactor.go View File

@ -25,7 +25,7 @@ const (
VoteChannel = byte(0x22) VoteChannel = byte(0x22)
VoteSetBitsChannel = byte(0x23) 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 blocksToContributeToBecomeGoodPeer = 10000
) )
@ -112,28 +112,28 @@ func (conR *ConsensusReactor) GetChannels() []*p2p.ChannelDescriptor {
ID: StateChannel, ID: StateChannel,
Priority: 5, Priority: 5,
SendQueueCapacity: 100, SendQueueCapacity: 100,
RecvMessageCapacity: maxConsensusMessageSize,
RecvMessageCapacity: maxMsgSize,
}, },
{ {
ID: DataChannel, // maybe split between gossiping current block and catchup stuff 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 Priority: 10, // once we gossip the whole block there's nothing left to send until next height or round
SendQueueCapacity: 100, SendQueueCapacity: 100,
RecvBufferCapacity: 50 * 4096, RecvBufferCapacity: 50 * 4096,
RecvMessageCapacity: maxConsensusMessageSize,
RecvMessageCapacity: maxMsgSize,
}, },
{ {
ID: VoteChannel, ID: VoteChannel,
Priority: 5, Priority: 5,
SendQueueCapacity: 100, SendQueueCapacity: 100,
RecvBufferCapacity: 100 * 100, RecvBufferCapacity: 100 * 100,
RecvMessageCapacity: maxConsensusMessageSize,
RecvMessageCapacity: maxMsgSize,
}, },
{ {
ID: VoteSetBitsChannel, ID: VoteSetBitsChannel,
Priority: 1, Priority: 1,
SendQueueCapacity: 2, SendQueueCapacity: 2,
RecvBufferCapacity: 1024, RecvBufferCapacity: 1024,
RecvMessageCapacity: maxConsensusMessageSize,
RecvMessageCapacity: maxMsgSize,
}, },
} }
} }
@ -1314,6 +1314,10 @@ func RegisterConsensusMessages(cdc *amino.Codec) {
// DecodeMessage decodes the given bytes into a ConsensusMessage. // DecodeMessage decodes the given bytes into a ConsensusMessage.
func DecodeMessage(bz []byte) (msg ConsensusMessage, err error) { 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) err = cdc.UnmarshalBinaryBare(bz, &msg)
return return
} }


+ 8
- 3
evidence/reactor.go View File

@ -2,11 +2,12 @@ package evidence
import ( import (
"fmt" "fmt"
"github.com/tendermint/go-amino"
"github.com/tendermint/tmlibs/log"
"reflect" "reflect"
"time" "time"
"github.com/tendermint/go-amino"
"github.com/tendermint/tmlibs/log"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )
@ -14,7 +15,7 @@ import (
const ( const (
EvidenceChannel = byte(0x38) EvidenceChannel = byte(0x38)
maxEvidenceMessageSize = 1048576 // 1MB TODO make it configurable
maxMsgSize = 1048576 // 1MB TODO make it configurable
broadcastEvidenceIntervalS = 60 // broadcast uncommitted evidence this often broadcastEvidenceIntervalS = 60 // broadcast uncommitted evidence this often
) )
@ -146,6 +147,10 @@ func RegisterEvidenceMessages(cdc *amino.Codec) {
// DecodeMessage decodes a byte-array into a EvidenceMessage. // DecodeMessage decodes a byte-array into a EvidenceMessage.
func DecodeMessage(bz []byte) (msg EvidenceMessage, err error) { 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) err = cdc.UnmarshalBinaryBare(bz, &msg)
return return
} }


+ 5
- 1
mempool/reactor.go View File

@ -18,7 +18,7 @@ import (
const ( const (
MempoolChannel = byte(0x30) 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 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. // DecodeMessage decodes a byte-array into a MempoolMessage.
func DecodeMessage(bz []byte) (msg MempoolMessage, err error) { 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) err = cdc.UnmarshalBinaryBare(bz, &msg)
return return
} }


+ 5
- 1
p2p/pex/pex_reactor.go View File

@ -21,7 +21,7 @@ const (
// PexChannel is a channel for PEX messages // PexChannel is a channel for PEX messages
PexChannel = byte(0x00) PexChannel = byte(0x00)
maxPexMessageSize = 1048576 // 1MB
maxMsgSize = 1048576 // 1MB
// ensure we have enough peers // ensure we have enough peers
defaultEnsurePeersPeriod = 30 * time.Second defaultEnsurePeersPeriod = 30 * time.Second
@ -616,6 +616,10 @@ func RegisterPexMessage(cdc *amino.Codec) {
// DecodeMessage implements interface registered above. // DecodeMessage implements interface registered above.
func DecodeMessage(bz []byte) (msg PexMessage, err error) { 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) err = cdc.UnmarshalBinary(bz, &msg)
return return
} }


+ 0
- 1
types/priv_validator.go View File

@ -92,5 +92,4 @@ func (pv *MockPV) String() string {
func (pv *MockPV) DisableChecks() { func (pv *MockPV) DisableChecks() {
// Currently this does nothing, // Currently this does nothing,
// as MockPV has no safety checks at all. // as MockPV has no safety checks at all.
return
} }

Loading…
Cancel
Save