check max msg size in DecodeMessage

This commit is contained in:
Ethan Buchman
2018-04-09 15:14:33 +03:00
parent bb1b249e8a
commit 1a1e4e767b
6 changed files with 33 additions and 13 deletions

View File

@@ -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
}