vm: restrict max size in APPEND
This commit is contained in:
parent
8abcaeee6f
commit
2d56c66bde
2 changed files with 24 additions and 0 deletions
|
@ -786,10 +786,16 @@ func (v *VM) execute(ctx *Context, op Instruction, parameter []byte) {
|
|||
switch t := arrElem.value.(type) {
|
||||
case *ArrayItem:
|
||||
arr := t.Value().([]StackItem)
|
||||
if len(arr) >= MaxArraySize {
|
||||
panic("too long array")
|
||||
}
|
||||
arr = append(arr, val)
|
||||
t.value = arr
|
||||
case *StructItem:
|
||||
arr := t.Value().([]StackItem)
|
||||
if len(arr) >= MaxArraySize {
|
||||
panic("too long struct")
|
||||
}
|
||||
arr = append(arr, val)
|
||||
t.value = arr
|
||||
default:
|
||||
|
|
|
@ -652,6 +652,24 @@ func TestAPPENDWrongType(t *testing.T) {
|
|||
assert.Equal(t, true, vm.HasFailed())
|
||||
}
|
||||
|
||||
func TestAPPENDGoodSizeLimit(t *testing.T) {
|
||||
prog := makeProgram(NEWARRAY, DUP, PUSH0, APPEND)
|
||||
vm := load(prog)
|
||||
vm.estack.PushVal(MaxArraySize - 1)
|
||||
vm.Run()
|
||||
assert.Equal(t, false, vm.state.HasFlag(faultState))
|
||||
assert.Equal(t, 1, vm.estack.Len())
|
||||
assert.Equal(t, MaxArraySize, len(vm.estack.Pop().Array()))
|
||||
}
|
||||
|
||||
func TestAPPENDBadSizeLimit(t *testing.T) {
|
||||
prog := makeProgram(NEWARRAY, DUP, PUSH0, APPEND)
|
||||
vm := load(prog)
|
||||
vm.estack.PushVal(MaxArraySize)
|
||||
vm.Run()
|
||||
assert.Equal(t, true, vm.state.HasFlag(faultState))
|
||||
}
|
||||
|
||||
func TestPICKITEMBadIndex(t *testing.T) {
|
||||
prog := makeProgram(PICKITEM)
|
||||
vm := load(prog)
|
||||
|
|
Loading…
Reference in a new issue