Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IndexOutOfRangeExceptions from IsMultiSigContract #1890

Merged
merged 2 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
};
case2.IsMultiSigContract();
shargon marked this conversation as resolved.
Show resolved Hide resolved
}
}
}