Skip to content

Commit e71031e

Browse files
committed
triedb/pathdb: check result
1 parent 78ff991 commit e71031e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

triedb/pathdb/history_trienode.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,19 @@ func decodeSingle(keySection []byte, onValue func([]byte, int, int) error) ([]st
387387
}
388388
// Resolve the entry from key section
389389
nShared, nn := binary.Uvarint(keySection[keyOff:]) // key length shared (varint)
390+
if nn <= 0 {
391+
return nil, fmt.Errorf("corrupted varint encoding for nShared at offset %d", keyOff)
392+
}
390393
keyOff += nn
391394
nUnshared, nn := binary.Uvarint(keySection[keyOff:]) // key length not shared (varint)
395+
if nn <= 0 {
396+
return nil, fmt.Errorf("corrupted varint encoding for nUnshared at offset %d", keyOff)
397+
}
392398
keyOff += nn
393399
nValue, nn := binary.Uvarint(keySection[keyOff:]) // value length (varint)
400+
if nn <= 0 {
401+
return nil, fmt.Errorf("corrupted varint encoding for nValue at offset %d", keyOff)
402+
}
394403
keyOff += nn
395404

396405
// Validate that the values can fit in an int to prevent overflow on 32-bit systems

0 commit comments

Comments
 (0)