Skip to content

Commit 11c0fb9

Browse files
authored
triedb/pathdb: fix index out of range panic in decodeSingle (#32937)
Fixes TestCorruptedKeySection flaky test failure. https://github.com/ethereum/go-ethereum/actions/runs/18600235182/job/53037084761?pr=32920
1 parent 88576c5 commit 11c0fb9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

triedb/pathdb/history_trienode.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,15 @@ func decodeSingle(keySection []byte, onValue func([]byte, int, int) error) ([]st
370370
for keyOff < keyLimit {
371371
// Validate the key and value offsets within the single trie data chunk
372372
if items%trienodeDataBlockRestartLen == 0 {
373-
if keyOff != int(keyOffsets[items/trienodeDataBlockRestartLen]) {
374-
return nil, fmt.Errorf("key offset is not matched, recorded: %d, want: %d", keyOffsets[items/trienodeDataBlockRestartLen], keyOff)
373+
restartIndex := items / trienodeDataBlockRestartLen
374+
if restartIndex >= len(keyOffsets) {
375+
return nil, fmt.Errorf("restart index out of range: %d, available restarts: %d", restartIndex, len(keyOffsets))
375376
}
376-
if valOff != int(valOffsets[items/trienodeDataBlockRestartLen]) {
377-
return nil, fmt.Errorf("value offset is not matched, recorded: %d, want: %d", valOffsets[items/trienodeDataBlockRestartLen], valOff)
377+
if keyOff != int(keyOffsets[restartIndex]) {
378+
return nil, fmt.Errorf("key offset is not matched, recorded: %d, want: %d", keyOffsets[restartIndex], keyOff)
379+
}
380+
if valOff != int(valOffsets[restartIndex]) {
381+
return nil, fmt.Errorf("value offset is not matched, recorded: %d, want: %d", valOffsets[restartIndex], valOff)
378382
}
379383
}
380384
// Resolve the entry from key section

0 commit comments

Comments
 (0)