Skip to content

Commit 78ff991

Browse files
committed
triedb/pathdb: fix 32-bit integer overflow in history trienode decoder
1 parent 28c59b7 commit 78ff991

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

triedb/pathdb/history_trienode.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package pathdb
1919
import (
2020
"bytes"
2121
"encoding/binary"
22+
"errors"
2223
"fmt"
2324
"iter"
2425
"maps"
@@ -392,6 +393,12 @@ func decodeSingle(keySection []byte, onValue func([]byte, int, int) error) ([]st
392393
nValue, nn := binary.Uvarint(keySection[keyOff:]) // value length (varint)
393394
keyOff += nn
394395

396+
// Validate that the values can fit in an int to prevent overflow on 32-bit systems
397+
const maxInt = int(^uint(0) >> 1)
398+
if nShared > uint64(maxInt) || nUnshared > uint64(maxInt) || nValue > uint64(maxInt) {
399+
return nil, errors.New("key size too large")
400+
}
401+
395402
// Resolve unshared key
396403
if keyOff+int(nUnshared) > len(keySection) {
397404
return nil, fmt.Errorf("key length too long, unshared key length: %d, off: %d, section size: %d", nUnshared, keyOff, len(keySection))

0 commit comments

Comments
 (0)