patch 8.1.1720: crash with very long %[] pattern
Problem: Crash with very long %[] pattern. (Reza Mirzazade farkhani)
Solution: Check for reg_toolong. (closes #4703)
diff --git a/src/regexp.c b/src/regexp.c
index 5676044..7d0ac60 100644
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -2175,7 +2175,11 @@
if (ret == NULL)
ret = br;
else
+ {
regtail(lastnode, br);
+ if (reg_toolong)
+ return NULL;
+ }
ungetchr();
one_exactly = TRUE;
@@ -2200,6 +2204,8 @@
if (OP(br) == BRANCH)
{
regtail(br, lastbranch);
+ if (reg_toolong)
+ return NULL;
br = OPERAND(br);
}
else
diff --git a/src/testdir/test_regexp_utf8.vim b/src/testdir/test_regexp_utf8.vim
index 98b9e73..19ff882 100644
--- a/src/testdir/test_regexp_utf8.vim
+++ b/src/testdir/test_regexp_utf8.vim
@@ -206,3 +206,12 @@
call assert_equal(1, "\u3042" =~# '[\u3000-\u4000]')
set re=0
endfunc
+
+func Test_optmatch_toolong()
+ set re=1
+ " Can only handle about 8000 characters.
+ let pat = '\\%[' .. repeat('x', 9000) .. ']'
+ call assert_fails('call match("abc def", "' .. pat .. '")', 'E339:')
+ set re=0
+endfunc
+
diff --git a/src/version.c b/src/version.c
index 0de9887..7568186 100644
--- a/src/version.c
+++ b/src/version.c
@@ -778,6 +778,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1720,
+/**/
1719,
/**/
1718,