mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
pathdb: fix pathBloomHash calc panic
This commit is contained in:
parent
f31105d285
commit
37c54c7aa5
1 changed files with 10 additions and 12 deletions
|
|
@ -85,21 +85,19 @@ func nodeBloomHash(h common.Hash, p []byte) uint64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func pathBloomHash(p []byte) uint64 {
|
func pathBloomHash(p []byte) uint64 {
|
||||||
if len(p)&1 != 0 {
|
if len(p) > 16 {
|
||||||
panic("can't convert hex key of odd length")
|
panic("invalid path")
|
||||||
}
|
}
|
||||||
hashLen := len(p) / 2
|
var result uint64
|
||||||
if hashLen > 8 {
|
for _, nibble := range p {
|
||||||
panic("hash value too long")
|
// 检查每个 nibble 是否在有效范围内(0-15)
|
||||||
|
if nibble > 0x0F {
|
||||||
|
panic("invalid path nibble value")
|
||||||
|
}
|
||||||
|
result = (result << 4) | uint64(nibble)
|
||||||
}
|
}
|
||||||
|
|
||||||
var hashValue uint64
|
return uint64(len(p))<<32 + result
|
||||||
for i := 0; i < hashLen; i++ {
|
|
||||||
hashValue <<= 8
|
|
||||||
hashValue |= uint64(p[i*2])<<4 | uint64(p[i*2+1])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (uint64(hashLen) << 32) | (hashValue << 1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// diffLayer represents a collection of modifications made to the in-memory tries
|
// diffLayer represents a collection of modifications made to the in-memory tries
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue