diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index c9bc97d2b..db03e6deb 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -375,7 +375,7 @@ func (v *VM) execute(ctx *Context, op Instruction) { case XTUCK: n := int(v.estack.Pop().BigInt().Int64()) - if n < 0 { + if n <= 0 { panic("XTUCK: invalid length") } a := v.estack.Dup(0) diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index 5a7f5771a..a0682c1ab 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -658,6 +658,15 @@ func TestXTUCKbadNegative(t *testing.T) { assert.Equal(t, true, vm.state.HasFlag(faultState)) } +func TestXTUCKbadZero(t *testing.T) { + prog := makeProgram(XTUCK) + vm := load(prog) + vm.estack.PushVal(1) + vm.estack.PushVal(0) + vm.Run() + assert.Equal(t, true, vm.state.HasFlag(faultState)) +} + func TestXTUCKgood(t *testing.T) { prog := makeProgram(XTUCK) topelement := 5