From f523b2a501e1b55860e4db856c568691995012e1 Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Fri, 28 Mar 2025 16:38:28 +0800 Subject: [PATCH] ethdb: check key length to prevent hash computation --- ethdb/leveldb/leveldb.go | 2 +- ethdb/pebble/pebble.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ethdb/leveldb/leveldb.go b/ethdb/leveldb/leveldb.go index e04e7c5bea..6e3e1efdbb 100644 --- a/ethdb/leveldb/leveldb.go +++ b/ethdb/leveldb/leveldb.go @@ -232,7 +232,7 @@ func (db *Database) DeleteRange(start, end []byte) error { }() for it.Next() && bytes.Compare(end, it.Key()) > 0 { // Prevent deletion for trie nodes in hash mode - if h := crypto.HashData(buff, it.Value()); h == common.BytesToHash(it.Key()) { + if len(it.Key()) == 32 && crypto.HashData(buff, it.Value()) == common.BytesToHash(it.Key()) { ignored++ continue } diff --git a/ethdb/pebble/pebble.go b/ethdb/pebble/pebble.go index 423d0b3a52..d2cf7c18a5 100644 --- a/ethdb/pebble/pebble.go +++ b/ethdb/pebble/pebble.go @@ -370,7 +370,7 @@ func (d *Database) DeleteRange(start, end []byte) error { }() for it.Next() && bytes.Compare(end, it.Key()) > 0 { // Prevent deletion for trie nodes in hash mode - if h := crypto.HashData(buff, it.Value()); h == common.BytesToHash(it.Key()) { + if len(it.Key()) == 32 && crypto.HashData(buff, it.Value()) == common.BytesToHash(it.Key()) { ignored++ continue }