forked from TrueCloudLab/neoneo-go
vm: restrict max size in SETITEM
This commit is contained in:
parent
6f1f9e56bb
commit
6d7016c3b9
2 changed files with 35 additions and 0 deletions
|
@ -871,6 +871,9 @@ func (v *VM) execute(ctx *Context, op Instruction, parameter []byte) {
|
|||
}
|
||||
arr[index] = item
|
||||
case *MapItem:
|
||||
if !t.Has(key.value) && len(t.value) >= MaxArraySize {
|
||||
panic("too big map")
|
||||
}
|
||||
t.Add(key.value, item)
|
||||
|
||||
default:
|
||||
|
|
|
@ -734,6 +734,38 @@ func TestSETITEMMap(t *testing.T) {
|
|||
assert.Equal(t, makeStackItem([]byte{0, 1}), vm.estack.Pop().value)
|
||||
}
|
||||
|
||||
func TestSETITEMBigMapBad(t *testing.T) {
|
||||
prog := makeProgram(SETITEM)
|
||||
vm := load(prog)
|
||||
|
||||
m := NewMapItem()
|
||||
for i := 0; i < MaxArraySize; i++ {
|
||||
m.Add(makeStackItem(i), makeStackItem(i))
|
||||
}
|
||||
vm.estack.Push(&Element{value: m})
|
||||
vm.estack.PushVal(MaxArraySize)
|
||||
vm.estack.PushVal(0)
|
||||
|
||||
vm.Run()
|
||||
assert.Equal(t, true, vm.HasFailed())
|
||||
}
|
||||
|
||||
func TestSETITEMBigMapGood(t *testing.T) {
|
||||
prog := makeProgram(SETITEM)
|
||||
vm := load(prog)
|
||||
|
||||
m := NewMapItem()
|
||||
for i := 0; i < MaxArraySize; i++ {
|
||||
m.Add(makeStackItem(i), makeStackItem(i))
|
||||
}
|
||||
vm.estack.Push(&Element{value: m})
|
||||
vm.estack.PushVal(0)
|
||||
vm.estack.PushVal(0)
|
||||
|
||||
vm.Run()
|
||||
assert.Equal(t, false, vm.HasFailed())
|
||||
}
|
||||
|
||||
func TestSIZENoArgument(t *testing.T) {
|
||||
prog := makeProgram(SIZE)
|
||||
vm := load(prog)
|
||||
|
|
Loading…
Reference in a new issue