trie/bintrie: fix CollectNodes path slice aliasing

This commit is contained in:
CPerezz 2026-04-15 22:50:17 +02:00
parent d5969de518
commit 05773f4bae
No known key found for this signature in database
GPG key ID: 62045F34B97177DD

View file

@ -216,10 +216,16 @@ func (s *NodeStore) CollectNodes(ref NodeRef, path []byte, flushfn NodeFlushFn)
return nil
case KindInternal:
node := s.getInternal(ref.Index())
if err := s.CollectNodes(node.left, append(path, 0), flushfn); err != nil {
leftPath := make([]byte, len(path)+1)
copy(leftPath, path)
leftPath[len(path)] = 0
if err := s.CollectNodes(node.left, leftPath, flushfn); err != nil {
return err
}
if err := s.CollectNodes(node.right, append(path, 1), flushfn); err != nil {
rightPath := make([]byte, len(path)+1)
copy(rightPath, path)
rightPath[len(path)] = 1
if err := s.CollectNodes(node.right, rightPath, flushfn); err != nil {
return err
}
flushfn(path, s.ComputeHash(ref), s.SerializeNode(ref))