From c08048eb84b47f21e4eb17981bcf6d6d7389ef09 Mon Sep 17 00:00:00 2001 From: CPerezz Date: Sun, 19 Apr 2026 22:15:38 +0200 Subject: [PATCH] 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. --- trie/bintrie/node_ref.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/trie/bintrie/node_ref.go b/trie/bintrie/node_ref.go index 8eea0b821f..793df7e225 100644 --- a/trie/bintrie/node_ref.go +++ b/trie/bintrie/node_ref.go @@ -42,7 +42,10 @@ const ( ) func makeRef(kind nodeKind, idx uint32) nodeRef { - return nodeRef(uint32(kind)< indexMask { + panic("nodeRef index overflow") + } + return nodeRef(uint32(kind)<> kindShift) }