mirror of
https://github.com/LBRYFoundation/lbcd.git
synced 2025-08-23 17:47:24 +00:00
wire/msgcfcheckpt: add sanity check for cf checkpoint parsing
This commit is contained in:
parent
53d846d68c
commit
7a657ffa2e
1 changed files with 15 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
||||||
package wire
|
package wire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
@ -15,8 +16,17 @@ const (
|
||||||
// CFCheckptInterval is the gap (in number of blocks) between each
|
// CFCheckptInterval is the gap (in number of blocks) between each
|
||||||
// filter header checkpoint.
|
// filter header checkpoint.
|
||||||
CFCheckptInterval = 1000
|
CFCheckptInterval = 1000
|
||||||
|
|
||||||
|
// maxCFHeadersLen is the max number of filter headers we will attempt
|
||||||
|
// to decode.
|
||||||
|
maxCFHeadersLen = 100000
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrInsaneCFHeaderCount signals that we were asked to decode an
|
||||||
|
// unreasonable number of cfilter headers.
|
||||||
|
var ErrInsaneCFHeaderCount = errors.New(
|
||||||
|
"refusing to decode unreasonable number of filter headers")
|
||||||
|
|
||||||
// MsgCFCheckpt implements the Message interface and represents a bitcoin
|
// MsgCFCheckpt implements the Message interface and represents a bitcoin
|
||||||
// cfcheckpt message. It is used to deliver committed filter header information
|
// cfcheckpt message. It is used to deliver committed filter header information
|
||||||
// in response to a getcfcheckpt message (MsgGetCFCheckpt). See MsgGetCFCheckpt
|
// in response to a getcfcheckpt message (MsgGetCFCheckpt). See MsgGetCFCheckpt
|
||||||
|
@ -60,6 +70,11 @@ func (msg *MsgCFCheckpt) BtcDecode(r io.Reader, pver uint32, _ MessageEncoding)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Refuse to decode an insane number of cfheaders.
|
||||||
|
if count > maxCFHeadersLen {
|
||||||
|
return ErrInsaneCFHeaderCount
|
||||||
|
}
|
||||||
|
|
||||||
// Create a contiguous slice of hashes to deserialize into in order to
|
// Create a contiguous slice of hashes to deserialize into in order to
|
||||||
// reduce the number of allocations.
|
// reduce the number of allocations.
|
||||||
msg.FilterHeaders = make([]*chainhash.Hash, count)
|
msg.FilterHeaders = make([]*chainhash.Hash, count)
|
||||||
|
|
Loading…
Add table
Reference in a new issue