mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-04 19:19:44 +00:00
Merge pull request #973 from nspcc-dev/fix/refcount
vm: update stack size in SETITEM properly
This commit is contained in:
commit
e07fd4f9f0
2 changed files with 22 additions and 2 deletions
|
@ -1051,8 +1051,8 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
|||
arr[index] = item
|
||||
v.estack.updateSizeAdd(arr[index])
|
||||
case *MapItem:
|
||||
if t.Has(key.value) {
|
||||
v.estack.updateSizeRemove(item)
|
||||
if i := t.Index(key.value); i >= 0 {
|
||||
v.estack.updateSizeRemove(t.value[i].Value)
|
||||
} else if len(t.value) >= MaxArraySize {
|
||||
panic("too big map")
|
||||
}
|
||||
|
|
|
@ -1442,6 +1442,26 @@ func TestSETITEMBigMapBad(t *testing.T) {
|
|||
checkVMFailed(t, vm)
|
||||
}
|
||||
|
||||
// This test checks is SETITEM properly updates reference counter.
|
||||
// 1. Create 2 arrays of size MaxArraySize - 3. (MaxStackSize = 2 * MaxArraySize)
|
||||
// 2. SETITEM each of them to a map.
|
||||
// 3. Replace each of them with a scalar value.
|
||||
func TestSETITEMMapStackLimit(t *testing.T) {
|
||||
size := MaxArraySize - 3
|
||||
m := NewMapItem()
|
||||
m.Add(NewBigIntegerItem(1), NewArrayItem(makeArrayOfFalses(size)))
|
||||
m.Add(NewBigIntegerItem(2), NewArrayItem(makeArrayOfFalses(size)))
|
||||
|
||||
prog := makeProgram(
|
||||
opcode.DUP, opcode.PUSH1, opcode.PUSH1, opcode.SETITEM,
|
||||
opcode.DUP, opcode.PUSH2, opcode.PUSH2, opcode.SETITEM,
|
||||
opcode.DUP, opcode.PUSH3, opcode.PUSH3, opcode.SETITEM,
|
||||
opcode.DUP, opcode.PUSH4, opcode.PUSH4, opcode.SETITEM)
|
||||
v := load(prog)
|
||||
v.estack.PushVal(m)
|
||||
runVM(t, v)
|
||||
}
|
||||
|
||||
func TestSETITEMBigMapGood(t *testing.T) {
|
||||
prog := makeProgram(opcode.SETITEM)
|
||||
vm := load(prog)
|
||||
|
|
Loading…
Reference in a new issue