From 1721360dd125dc92ba8aada5a8b55d9afa8a2d67 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 21 May 2020 12:16:38 +0300 Subject: [PATCH] vm: limit types accepted for PICKITEM, fix #965 bafdb916a0bd9a5408e7d98b95c1a038305a8773 change was wrong (probably brought from neo-vm 3.0 at the state at which it existed back then), neo-vm 2.x doesn't allow PICKITEM for arbitrary types. --- pkg/vm/vm.go | 7 +------ pkg/vm/vm_test.go | 4 +--- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index aeb8b0180..9a022e75a 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -1029,12 +1029,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro } v.estack.Push(&Element{value: t.value[index].Value.Dup()}) default: - arr := obj.Bytes() - if index < 0 || index >= len(arr) { - panic("PICKITEM: invalid index") - } - item := arr[index] - v.estack.PushVal(int(item)) + panic("PICKITEM: unknown type") } case opcode.SETITEM: diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index aab31a408..34c5ddab2 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -1367,9 +1367,7 @@ func TestPICKITEMByteArray(t *testing.T) { vm := load(prog) vm.estack.PushVal([]byte{1, 2}) vm.estack.PushVal(1) - runVM(t, vm) - assert.Equal(t, 1, vm.estack.Len()) - assert.Equal(t, makeStackItem(2), vm.estack.Pop().value) + checkVMFailed(t, vm) } func TestPICKITEMDupArray(t *testing.T) {