From 5500195d586cc548461f19d9aab7d19c1e7a123e Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 29 Jul 2020 11:28:29 +0300 Subject: [PATCH] stackitem: ensure map keys are a valid UTF-8 --- pkg/vm/stackitem/json.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/vm/stackitem/json.go b/pkg/vm/stackitem/json.go index 81b67f769..97d25f883 100644 --- a/pkg/vm/stackitem/json.go +++ b/pkg/vm/stackitem/json.go @@ -64,9 +64,17 @@ func toJSON(buf *io.BufBinWriter, item Item) { case *Map: w.WriteB('{') for i := range it.value { - bs, _ := it.value[i].Key.TryBytes() // map key can always be converted to []byte + // map key can always be converted to []byte + // but are not always a valid UTF-8. + key, err := ToString(it.value[i].Key) + if err != nil { + if buf.Err == nil { + buf.Err = err + } + return + } w.WriteB('"') - w.WriteBytes(bs) + w.WriteBytes([]byte(key)) w.WriteBytes([]byte(`":`)) toJSON(buf, it.value[i].Value) if i < len(it.value)-1 {