From e2121ff583e267d484100cde1c207aa26d7887af Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 7 Apr 2021 14:52:50 +0300 Subject: [PATCH] core: fix key clashes in Storage.Find Fixes #1873. NewByteArray() doesn't copy the slice, so we need to do it ourselves. --- pkg/core/interop_neo.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/core/interop_neo.go b/pkg/core/interop_neo.go index 39220a0ee..a5dce2399 100644 --- a/pkg/core/interop_neo.go +++ b/pkg/core/interop_neo.go @@ -49,7 +49,10 @@ func storageFind(ic *interop.Context) error { filteredMap := stackitem.NewMap() for k, v := range siMap { - filteredMap.Add(stackitem.NewByteArray(append(prefix, []byte(k)...)), stackitem.NewByteArray(v)) + key := append(prefix, []byte(k)...) + keycopy := make([]byte, len(key)) + copy(keycopy, key) + filteredMap.Add(stackitem.NewByteArray(keycopy), stackitem.NewByteArray(v)) } sort.Slice(filteredMap.Value().([]stackitem.MapElement), func(i, j int) bool { return bytes.Compare(filteredMap.Value().([]stackitem.MapElement)[i].Key.Value().([]byte),