mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
triedb/pathdb: fix 32-bit integer overflow in history trienode decoder
This commit is contained in:
parent
28c59b7a76
commit
78ff9911c5
1 changed files with 7 additions and 0 deletions
|
|
@ -19,6 +19,7 @@ package pathdb
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"iter"
|
"iter"
|
||||||
"maps"
|
"maps"
|
||||||
|
|
@ -392,6 +393,12 @@ func decodeSingle(keySection []byte, onValue func([]byte, int, int) error) ([]st
|
||||||
nValue, nn := binary.Uvarint(keySection[keyOff:]) // value length (varint)
|
nValue, nn := binary.Uvarint(keySection[keyOff:]) // value length (varint)
|
||||||
keyOff += nn
|
keyOff += nn
|
||||||
|
|
||||||
|
// Validate that the values can fit in an int to prevent overflow on 32-bit systems
|
||||||
|
const maxInt = int(^uint(0) >> 1)
|
||||||
|
if nShared > uint64(maxInt) || nUnshared > uint64(maxInt) || nValue > uint64(maxInt) {
|
||||||
|
return nil, errors.New("key size too large")
|
||||||
|
}
|
||||||
|
|
||||||
// Resolve unshared key
|
// Resolve unshared key
|
||||||
if keyOff+int(nUnshared) > len(keySection) {
|
if keyOff+int(nUnshared) > len(keySection) {
|
||||||
return nil, fmt.Errorf("key length too long, unshared key length: %d, off: %d, section size: %d", nUnshared, keyOff, len(keySection))
|
return nil, fmt.Errorf("key length too long, unshared key length: %d, off: %d, section size: %d", nUnshared, keyOff, len(keySection))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue