vm: restrict max size in PACK
This commit is contained in:
parent
2d56c66bde
commit
6f1f9e56bb
2 changed files with 12 additions and 1 deletions
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue