vm: restrict max size in PACK

This commit is contained in:
Evgenii Stratonikov 2019-10-17 11:07:44 +03:00
parent 2d56c66bde
commit 6f1f9e56bb
2 changed files with 12 additions and 1 deletions

View file

@ -804,7 +804,7 @@ func (v *VM) execute(ctx *Context, op Instruction, parameter []byte) {
case PACK:
n := int(v.estack.Pop().BigInt().Int64())
if n < 0 || n > v.estack.Len() {
if n < 0 || n > v.estack.Len() || n > MaxArraySize {
panic("OPACK: invalid length")
}

View file

@ -1604,6 +1604,17 @@ func TestPACKBadLen(t *testing.T) {
assert.Equal(t, true, vm.HasFailed())
}
func TestPACKBigLen(t *testing.T) {
prog := makeProgram(PACK)
vm := load(prog)
for i := 0; i <= MaxArraySize; i++ {
vm.estack.PushVal(0)
}
vm.estack.PushVal(MaxArraySize + 1)
vm.Run()
assert.Equal(t, true, vm.HasFailed())
}
func TestPACKGoodZeroLen(t *testing.T) {
prog := makeProgram(PACK)
vm := load(prog)