@@ -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