vm: limit types accepted for PICKITEM, fix #965

bafdb916a0 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.
This commit is contained in:
Roman Khimov 2020-05-21 12:16:38 +03:00
parent 328c6d7ce5
commit 1721360dd1
2 changed files with 2 additions and 9 deletions

View file

@ -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()}) v.estack.Push(&Element{value: t.value[index].Value.Dup()})
default: default:
arr := obj.Bytes() panic("PICKITEM: unknown type")
if index < 0 || index >= len(arr) {
panic("PICKITEM: invalid index")
}
item := arr[index]
v.estack.PushVal(int(item))
} }
case opcode.SETITEM: case opcode.SETITEM:

View file

@ -1367,9 +1367,7 @@ func TestPICKITEMByteArray(t *testing.T) {
vm := load(prog) vm := load(prog)
vm.estack.PushVal([]byte{1, 2}) vm.estack.PushVal([]byte{1, 2})
vm.estack.PushVal(1) vm.estack.PushVal(1)
runVM(t, vm) checkVMFailed(t, vm)
assert.Equal(t, 1, vm.estack.Len())
assert.Equal(t, makeStackItem(2), vm.estack.Pop().value)
} }
func TestPICKITEMDupArray(t *testing.T) { func TestPICKITEMDupArray(t *testing.T) {