diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 6b838752f..ca68a2716 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -659,7 +659,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro panic("invalid destination index") } dst := v.estack.Pop().value.(*stackitem.Buffer).Value().([]byte) - if sum := si + n; sum < 0 || sum > len(dst) { + if sum := di + n; sum < 0 || sum > len(dst) { panic("size is too big") } copy(dst[di:], src[si:si+n]) diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index 24e0a3150..65c51e2d4 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -1344,6 +1344,10 @@ func TestMEMCPY(t *testing.T) { buf := stackitem.NewBuffer([]byte{0, 1, 2, 3}) runWithArgs(t, prog, stackitem.NewBuffer([]byte{0, 6, 7, 3}), buf, buf, 1, []byte{4, 5, 6, 7}, 2, 2) }) + t.Run("NonZeroDstIndex", func(t *testing.T) { + buf := stackitem.NewBuffer([]byte{0, 1, 2}) + runWithArgs(t, prog, stackitem.NewBuffer([]byte{0, 6, 7}), buf, buf, 1, []byte{4, 5, 6, 7}, 2, 2) + }) t.Run("NegativeSize", getTestFuncForVM(prog, nil, stackitem.NewBuffer([]byte{0, 1}), 0, []byte{2}, 0, -1)) t.Run("NegativeSrcIndex", getTestFuncForVM(prog, nil, stackitem.NewBuffer([]byte{0, 1}), 0, []byte{2}, -1, 1)) t.Run("NegativeDstIndex", getTestFuncForVM(prog, nil, stackitem.NewBuffer([]byte{0, 1}), -1, []byte{2}, 0, 1))