Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
Fix Instruction error (#518)
Browse files Browse the repository at this point in the history
* Fix Instruction error

* Update src/Neo.VM/Instruction.cs

* Update src/Neo.VM/Instruction.cs

* Update src/Neo.VM/Instruction.cs

* Update src/Neo.VM/Instruction.cs

---------

Co-authored-by: Jimmy <jinghui@wayne.edu>
  • Loading branch information
shargon and Jim8y committed Nov 12, 2023
1 parent 426e54d commit 1096b03
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Neo.VM/Instruction.cs
Expand Up @@ -205,14 +205,21 @@ internal Instruction(ReadOnlyMemory<byte> script, int ip) : this((OpCode)script.
operandSize = OperandSizeTable[(int)OpCode];
break;
case 1:
if (ip >= span.Length)
throw new BadScriptException($"Instruction out of bounds. InstructionPointer: {ip}");
operandSize = span[ip];
break;
case 2:
if (ip + 1 >= span.Length)
throw new BadScriptException($"Instruction out of bounds. InstructionPointer: {ip}");
operandSize = BinaryPrimitives.ReadUInt16LittleEndian(span[ip..]);
break;
case 4:
if (ip + 3 >= span.Length)
throw new BadScriptException($"Instruction out of bounds. InstructionPointer: {ip}");
operandSize = BinaryPrimitives.ReadInt32LittleEndian(span[ip..]);
if (operandSize < 0) throw new BadScriptException();
if (operandSize < 0)
throw new BadScriptException($"Instruction out of bounds. InstructionPointer: {ip}, operandSize: {operandSize}");
break;
}
ip += operandSizePrefix;
Expand Down
9 changes: 9 additions & 0 deletions tests/Neo.VM.Tests/UtScript.cs
Expand Up @@ -35,6 +35,15 @@ public void StrictMode()

var script = new Script(rawScript, false);
Assert.AreEqual(2, script.Length);

rawScript = new byte[] { (byte)OpCode.PUSHDATA1 };
Assert.ThrowsException<BadScriptException>(() => new Script(rawScript, true));

rawScript = new byte[] { (byte)OpCode.PUSHDATA2 };
Assert.ThrowsException<BadScriptException>(() => new Script(rawScript, true));

rawScript = new byte[] { (byte)OpCode.PUSHDATA4 };
Assert.ThrowsException<BadScriptException>(() => new Script(rawScript, true));
}

[TestMethod]
Expand Down

0 comments on commit 1096b03

Please sign in to comment.