ethdb: check key length to prevent hash computation

This commit is contained in:
Gary Rong 2025-03-28 16:38:28 +08:00
parent 86e3f1fc3a
commit f523b2a501
2 changed files with 2 additions and 2 deletions

View file

@ -232,7 +232,7 @@ func (db *Database) DeleteRange(start, end []byte) error {
}() }()
for it.Next() && bytes.Compare(end, it.Key()) > 0 { for it.Next() && bytes.Compare(end, it.Key()) > 0 {
// Prevent deletion for trie nodes in hash mode // 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++ ignored++
continue continue
} }

View file

@ -370,7 +370,7 @@ func (d *Database) DeleteRange(start, end []byte) error {
}() }()
for it.Next() && bytes.Compare(end, it.Key()) > 0 { for it.Next() && bytes.Compare(end, it.Key()) > 0 {
// Prevent deletion for trie nodes in hash mode // 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++ ignored++
continue continue
} }