vm: make LEFT fail if count is too big

This commit is contained in:
Evgenii Stratonikov 2020-05-21 09:43:35 +03:00
parent 22791272bf
commit 9dca2288ba
2 changed files with 2 additions and 2 deletions

View file

@ -694,7 +694,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
} }
s := v.estack.Pop().Bytes() s := v.estack.Pop().Bytes()
if t := len(s); l > t { if t := len(s); l > t {
l = t panic("size is too big")
} }
v.estack.PushVal(NewBufferItem(s[:l])) v.estack.PushVal(NewBufferItem(s[:l]))

View file

@ -1814,7 +1814,7 @@ func TestLEFT(t *testing.T) {
t.Run("NoString", getTestFuncForVM(prog, nil, 2)) t.Run("NoString", getTestFuncForVM(prog, nil, 2))
t.Run("NegativeLen", getTestFuncForVM(prog, nil, "abcdef", -1)) t.Run("NegativeLen", getTestFuncForVM(prog, nil, "abcdef", -1))
t.Run("Good", getTestFuncForVM(prog, NewBufferItem([]byte("ab")), "abcdef", 2)) 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) { func TestRIGHT(t *testing.T) {