Skip to content

Commit

Permalink
Fix IndexOutOfRangeExceptions from IsMultiSigContract (neo-project#1890)
Browse files Browse the repository at this point in the history
* Fix

* Update tests/neo.UnitTests/SmartContract/UT_Helper.cs

Co-authored-by: Erik van den Brink <git@erikvandenbrink.com>

Co-authored-by: Erik van den Brink <git@erikvandenbrink.com>
  • Loading branch information
2 people authored and cloud8little committed Jan 24, 2021
1 parent e018e57 commit 978c4ec
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/neo/SmartContract/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static bool IsMultiSigContract(byte[] script, out int m, out int n, List
switch (script[i])
{
case (byte)OpCode.PUSHINT8:
if (n != script[++i]) return false;
if (script.Length <= i + 1 || n != script[++i]) return false;
++i;
break;
case (byte)OpCode.PUSHINT16:
Expand All @@ -94,9 +94,9 @@ private static bool IsMultiSigContract(byte[] script, out int m, out int n, List
default:
return false;
}
if (script.Length != i + 6) return false;
if (script[i++] != (byte)OpCode.PUSHNULL) return false;
if (script[i++] != (byte)OpCode.SYSCALL) return false;
if (script.Length != i + 4) return false;
if (BitConverter.ToUInt32(script, i) != ApplicationEngine.Neo_Crypto_CheckMultisigWithECDsaSecp256r1)
return false;
return true;
Expand Down
31 changes: 31 additions & 0 deletions tests/neo.UnitTests/SmartContract/UT_Helper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.SmartContract;

namespace Neo.UnitTests.SmartContract
{
[TestClass]
public class UT_Helper
{
[TestMethod]
public void TestIsMultiSigContract()
{
var case1 = new byte[]
{
0, 2, 12, 33, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221,
221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 12, 33, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 0,
};
Assert.IsFalse(case1.IsMultiSigContract());

var case2 = new byte[]
{
18, 12, 33, 2, 111, 240, 59, 148, 146, 65, 206, 29, 173, 212, 53, 25, 230, 150, 14, 10, 133, 180, 26,
105, 160, 92, 50, 129, 3, 170, 43, 206, 21, 148, 202, 22, 12, 33, 2, 111, 240, 59, 148, 146, 65, 206,
29, 173, 212, 53, 25, 230, 150, 14, 10, 133, 180, 26, 105, 160, 92, 50, 129, 3, 170, 43, 206, 21, 148,
202, 22, 18
};
Assert.IsFalse(case2.IsMultiSigContract());
}
}
}

0 comments on commit 978c4ec

Please sign in to comment.