From a0d58b1f6fe3252d8122c9c1bb57ebc68e721f87 Mon Sep 17 00:00:00 2001 From: Shargon Date: Mon, 15 Jun 2020 13:26:10 +0200 Subject: [PATCH 1/2] Check ByteString --- src/neo/SmartContract/JsonSerializer.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/neo/SmartContract/JsonSerializer.cs b/src/neo/SmartContract/JsonSerializer.cs index 375709a13d..bbbda24442 100644 --- a/src/neo/SmartContract/JsonSerializer.cs +++ b/src/neo/SmartContract/JsonSerializer.cs @@ -48,6 +48,11 @@ public static JObject Serialize(StackItem item) foreach (var entry in map) { + if (!(entry.Key is ByteString)) + { + throw new FormatException(); + } + var key = entry.Key.GetString(); var value = Serialize(entry.Value); From a77ff09f338d9cd9c3ce26950b5587dd2a18e027 Mon Sep 17 00:00:00 2001 From: erikzhang Date: Tue, 16 Jun 2020 00:04:42 +0800 Subject: [PATCH 2/2] Fix SerializeToByteArray() --- src/neo/SmartContract/JsonSerializer.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/neo/SmartContract/JsonSerializer.cs b/src/neo/SmartContract/JsonSerializer.cs index bbbda24442..5ed1369c8c 100644 --- a/src/neo/SmartContract/JsonSerializer.cs +++ b/src/neo/SmartContract/JsonSerializer.cs @@ -48,10 +48,7 @@ public static JObject Serialize(StackItem item) foreach (var entry in map) { - if (!(entry.Key is ByteString)) - { - throw new FormatException(); - } + if (!(entry.Key is ByteString)) throw new FormatException(); var key = entry.Key.GetString(); var value = Serialize(entry.Value); @@ -111,6 +108,7 @@ public static byte[] SerializeToByteArray(StackItem item, uint maxSize) stack.Push(JsonTokenType.EndObject); foreach (var pair in map.Reverse()) { + if (!(pair.Key is ByteString)) throw new FormatException(); stack.Push(pair.Value); stack.Push(pair.Key); stack.Push(JsonTokenType.PropertyName); @@ -120,7 +118,7 @@ public static byte[] SerializeToByteArray(StackItem item, uint maxSize) writer.WriteEndObject(); break; case JsonTokenType.PropertyName: - writer.WritePropertyName(((PrimitiveType)stack.Pop()).GetSpan()); + writer.WritePropertyName(((ByteString)stack.Pop()).GetSpan()); break; case Null _: writer.WriteNullValue();