Skip to content

Commit

Permalink
Cleaner way
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Aug 16, 2023
1 parent 93b4126 commit be2ef40
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/Neo/SmartContract/ApplicationEngine.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using Neo.Cryptography.ECC;
using Neo.IO;
using Neo.Network.P2P.Payloads;
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.VM.Types;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using Array = Neo.VM.Types.Array;

namespace Neo.SmartContract
Expand Down Expand Up @@ -428,8 +428,18 @@ private static bool CheckItemType(StackItem item, ContractParameterType type)
return aType == StackItemType.Integer;
case ContractParameterType.ByteArray:
case ContractParameterType.String:
return aType is StackItemType.Any or StackItemType.ByteString or StackItemType.Buffer &&
Utility.StrictUTF8.GetString(item.GetSpan()) is not null; // Prevent any non-UTF8 string
{
if (aType is StackItemType.Any or StackItemType.ByteString or StackItemType.Buffer)
{
try
{
_ = Utility.StrictUTF8.GetString(item.GetSpan()); // Prevent any non-UTF8 string
return true;
}
catch { }
}
return false;
}
case ContractParameterType.Hash160:
if (aType == StackItemType.Any) return true;
if (aType != StackItemType.ByteString && aType != StackItemType.Buffer) return false;
Expand Down

0 comments on commit be2ef40

Please sign in to comment.