Skip to content

Commit 9bad465

Browse files
committed
Abandon pcre2test test if pattern conversion results in a string that is too long
1 parent 9323329 commit 9bad465

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ other tools that prefer the POSIX compatible unicode definition for \d.
8282

8383
20. Report the bit width of the library in use by pcre2test for usability.
8484

85+
21. A pathological pattern conversion test could result in a string longer than
86+
the available input buffer. Cause such a test to fail.
87+
8588

8689
Version 10.42 11-December-2022
8790
------------------------------

src/pcre2test.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5825,10 +5825,27 @@ if (pat_patctl.convert_type != CONVERT_UNSET)
58255825

58265826
else
58275827
{
5828+
BOOL toolong;
58285829
PCHARSV(converted_pattern, 0, converted_length, utf, outfile);
58295830
fprintf(outfile, "\n");
5830-
patlen = converted_length;
5831-
CONVERT_COPY(pbuffer, converted_pattern, converted_length + 1);
5831+
5832+
if (test_mode == PCRE8_MODE)
5833+
toolong = (converted_length + 1 > pbuffer8_size);
5834+
else if (test_mode == PCRE16_MODE)
5835+
toolong = (2*(converted_length + 1) > pbuffer8_size);
5836+
else /* 32-bit */
5837+
toolong = (4*(converted_length + 1) > pbuffer8_size);
5838+
5839+
if (toolong)
5840+
{
5841+
fprintf(outfile, "** Pattern conversion is too long for the buffer\n");
5842+
convert_return = PR_SKIP;
5843+
}
5844+
else
5845+
{
5846+
CONVERT_COPY(pbuffer, converted_pattern, converted_length + 1);
5847+
patlen = converted_length;
5848+
}
58325849
}
58335850

58345851
/* Free the converted pattern. */

testdata/testinput25

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@
1515

1616
/'>' c4 a3 '<'/hex,utf,convert_length=13
1717

18+
# This expansion creates a string that is too long for the input buffer.
19+
20+
/\[()]{65535}()/expand
21+
1822
# End of testinput25

testdata/testoutput25

Lines changed: 6 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)