Skip to content

Commit a179ccf

Browse files
authored
core/state: add bounds check in heap eviction loop (#33712)
core/state: add bounds check in heap eviction loop Add len(h) > 0 check before accessing h[0] to prevent potential panic and align with existing heap access patterns in txpool, p2p, and mclock packages.
1 parent c974722 commit a179ccf

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

core/state/state_sizer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func (t *SizeTracker) run() {
346346

347347
// Evict the stale statistics
348348
heap.Push(&h, stats[u.root])
349-
for u.blockNumber-h[0].BlockNumber > statEvictThreshold {
349+
for len(h) > 0 && u.blockNumber-h[0].BlockNumber > statEvictThreshold {
350350
delete(stats, h[0].StateRoot)
351351
heap.Pop(&h)
352352
}

0 commit comments

Comments
 (0)