From 9dca2288baaf403b6d813aff49936f63079ae3e0 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 21 May 2020 09:43:35 +0300 Subject: [PATCH] vm: make LEFT fail if count is too big --- pkg/vm/vm.go | 2 +- pkg/vm/vm_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index ba14f3700..1b3d93004 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -694,7 +694,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro } s := v.estack.Pop().Bytes() if t := len(s); l > t { - l = t + panic("size is too big") } v.estack.PushVal(NewBufferItem(s[:l])) diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index cb14a0fa7..d7a1666ef 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -1814,7 +1814,7 @@ func TestLEFT(t *testing.T) { t.Run("NoString", getTestFuncForVM(prog, nil, 2)) t.Run("NegativeLen", getTestFuncForVM(prog, nil, "abcdef", -1)) t.Run("Good", getTestFuncForVM(prog, NewBufferItem([]byte("ab")), "abcdef", 2)) - t.Run("GoodBigLen", getTestFuncForVM(prog, NewBufferItem([]byte("abcdef")), "abcdef", 8)) + t.Run("BadBigLen", getTestFuncForVM(prog, nil, "abcdef", 8)) } func TestRIGHT(t *testing.T) {