Skip to content

Commit ac36f52

Browse files
Fix out of bound issue in ContextStack operation (#1288)
1 parent 6bc4071 commit ac36f52

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

NBitcoin.Tests/script_tests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,20 @@ public void script_PushData()
10121012
AssertEx.StackEquals(pushdata4Stack.Stack, directStack.Stack);
10131013
}
10141014

1015+
[Fact]
1016+
[Trait("UnitTest", "UnitTest")]
1017+
public void script_OPNIP()
1018+
{
1019+
var context = new ScriptEvaluationContext()
1020+
{
1021+
ScriptVerify = ScriptVerify.P2SH
1022+
};
1023+
var directStack = context.Clone();
1024+
var direct = new Script(Encoders.Hex.DecodeData("000360670000005b770100000000005b770100000000000008777760779f00000877776077"));
1025+
var res = directStack.EvalScript(direct, new TransactionChecker(Network.CreateTransaction(), 0), HashVersion.Original);
1026+
Assert.True(res);
1027+
}
1028+
10151029
static Network Network => Network.Main;
10161030

10171031
[Fact]

NBitcoin/ScriptEvaluationContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2491,9 +2491,9 @@ public void Remove(int from)
24912491
public void Remove(int from, int to)
24922492
{
24932493
int toRemove = to - from;
2494-
for (int i = Count + from; i < Count + from + toRemove; i++)
2494+
for (int i = 0; i < toRemove; i++)
24952495
{
2496-
for (int y = Count + from; y < Count; y++)
2496+
for (int y = Count + from; y < Count - 1; y++)
24972497
_array[y] = _array[y + 1];
24982498
}
24992499
_position -= toRemove;

0 commit comments

Comments
 (0)