Skip to content

Commit

Permalink
Check Json.Serialize map keys (neo-project#1705)
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon authored and Tommo-L committed Jun 22, 2020
1 parent 1146cf6 commit 4a7e36e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/neo/SmartContract/JsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ 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);

Expand Down Expand Up @@ -106,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);
Expand All @@ -115,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();
Expand Down

0 comments on commit 4a7e36e

Please sign in to comment.