Skip to content

Commit f515080

Browse files
committed
Fix divide-by-zero in pcre2test
Fixes #728 Found by YinChen001 <497907957@qq.com>
1 parent d37c6df commit f515080

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/pcre2test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7620,7 +7620,7 @@ while ((c = *p++) != 0)
76207620
}
76217621

76227622
replen = CAST8VAR(q) - start_rep;
7623-
if (replen > (SIZE_MAX - needlen) / i)
7623+
if (i > 0 && replen > (SIZE_MAX - needlen) / i)
76247624
{
76257625
fprintf(outfile, "** Expanded content too large\n");
76267626
return PR_OK;

testdata/testinput2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4559,6 +4559,12 @@
45594559
/(abc)*/
45604560
\[abc]{5}
45614561

4562+
/(abc)*/
4563+
\[abc]{1}
4564+
4565+
/(abc)*/
4566+
\[abc]{0}
4567+
45624568
/^/gm
45634569
\n\n\n
45644570

testdata/testoutput2

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14772,6 +14772,15 @@ No match
1477214772
0: abcabcabcabcabc
1477314773
1: abc
1477414774

14775+
/(abc)*/
14776+
\[abc]{1}
14777+
0: abc
14778+
1: abc
14779+
14780+
/(abc)*/
14781+
\[abc]{0}
14782+
** Zero or negative repeat not allowed
14783+
1477514784
/^/gm
1477614785
\n\n\n
1477714786
0:

0 commit comments

Comments
 (0)