mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
prevent integer underflow in ReadAllHashesInRange
This commit is contained in:
parent
d2a5dba48f
commit
0dc323e853
1 changed files with 13 additions and 1 deletions
|
|
@ -20,6 +20,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
"slices"
|
||||
|
||||
|
|
@ -87,10 +88,21 @@ type NumberHash struct {
|
|||
// heights, both canonical and reorged forks included.
|
||||
// This method considers both limits to be _inclusive_.
|
||||
func ReadAllHashesInRange(db ethdb.Iteratee, first, last uint64) []*NumberHash {
|
||||
// Return empty result for inverted ranges
|
||||
if last < first {
|
||||
return nil
|
||||
}
|
||||
rangeLen := last - first
|
||||
var capHint int
|
||||
if rangeLen >= uint64(math.MaxInt) {
|
||||
capHint = math.MaxInt
|
||||
} else {
|
||||
capHint = int(rangeLen) + 1
|
||||
}
|
||||
var (
|
||||
start = encodeBlockNumber(first)
|
||||
keyLength = len(headerPrefix) + 8 + 32
|
||||
hashes = make([]*NumberHash, 0, 1+last-first)
|
||||
hashes = make([]*NumberHash, 0, capHint)
|
||||
it = db.NewIterator(headerPrefix, start)
|
||||
)
|
||||
defer it.Release()
|
||||
|
|
|
|||
Loading…
Reference in a new issue