mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-12 01:41:36 +00:00
trie/bintrie: panic on makeRef index overflow
Silently masking the index with indexMask would let an oversized idx collide with emptyRef (makeRef(kindEmpty, 0)): e.g. makeRef(kindEmpty, 1<<30) returned emptyRef, which IsEmpty would accept as absent even though the caller meant to reference a real node. Panic instead. allocInternal/allocStem/allocHashed already panic on pool overflow, so this is a belt-and-suspenders guard for any direct callers.
This commit is contained in:
parent
6e36636c9c
commit
c08048eb84
1 changed files with 4 additions and 1 deletions
|
|
@ -42,7 +42,10 @@ const (
|
|||
)
|
||||
|
||||
func makeRef(kind nodeKind, idx uint32) nodeRef {
|
||||
return nodeRef(uint32(kind)<<kindShift | (idx & indexMask))
|
||||
if idx > indexMask {
|
||||
panic("nodeRef index overflow")
|
||||
}
|
||||
return nodeRef(uint32(kind)<<kindShift | idx)
|
||||
}
|
||||
|
||||
func (r nodeRef) Kind() nodeKind { return nodeKind(uint32(r) >> kindShift) }
|
||||
|
|
|
|||
Loading…
Reference in a new issue