From 3fb01b0443069fa1ce915fdc7b7841a0469a62a6 Mon Sep 17 00:00:00 2001 From: "Philip.Hazel" Date: Sun, 29 Apr 2018 15:07:44 +0000 Subject: [PATCH] Ensure all match limit tests set a limit, don't rely on the default. --- ChangeLog | 4 ++++ src/pcre2_jit_test.c | 9 ++++++--- testdata/testinput15 | 13 +++++++++++++ testdata/testinput17 | 9 ++++++++- testdata/testinput6 | 1 + testdata/testoutput15 | 13 +++++++++++++ testdata/testoutput17 | 9 ++++++++- testdata/testoutput6 | 1 + 8 files changed, 54 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index f19f324..1aa9460 100644 --- a/ChangeLog +++ b/ChangeLog @@ -63,6 +63,10 @@ matches for the ovector, no matches were displayed. 14. Removed an occurrence of ctrl/Z from test 6 because Windows treats it as EOF. The test looks to have come from a fuzzer. +15. If PCRE2 was built with a default match limit a lot greater than the +default default of 10 000 000, some JIT tests of the match limit no longer +failed. All such tests now set 10 000 000 as the upper limit. + Version 10.31 12-February-2018 ------------------------------ diff --git a/src/pcre2_jit_test.c b/src/pcre2_jit_test.c index d9916b7..aadf241 100644 --- a/src/pcre2_jit_test.c +++ b/src/pcre2_jit_test.c @@ -1331,8 +1331,9 @@ static int regression_tests(void) ovector8_2[i] = -2; } if (re8) { + (void)pcre2_set_match_limit_8(mcontext8, 10000000); return_value8[1] = pcre2_match_8(re8, (PCRE2_SPTR8)current->input, strlen(current->input), - current->start_offset & OFFSET_MASK, current->match_options, mdata8_2, NULL); + current->start_offset & OFFSET_MASK, current->match_options, mdata8_2, mcontext8); if (pcre2_jit_compile_8(re8, jit_compile_mode)) { printf("\n8 bit: JIT compiler does not support \"%s\"\n", current->pattern); @@ -1375,8 +1376,9 @@ static int regression_tests(void) else length16 = copy_char8_to_char16((PCRE2_SPTR8)current->input, regtest_buf16, REGTEST_MAX_LENGTH16); + (void)pcre2_set_match_limit_16(mcontext16, 10000000); return_value16[1] = pcre2_match_16(re16, regtest_buf16, length16, - current->start_offset & OFFSET_MASK, current->match_options, mdata16_2, NULL); + current->start_offset & OFFSET_MASK, current->match_options, mdata16_2, mcontext16); if (pcre2_jit_compile_16(re16, jit_compile_mode)) { printf("\n16 bit: JIT compiler does not support \"%s\"\n", current->pattern); @@ -1419,8 +1421,9 @@ static int regression_tests(void) else length32 = copy_char8_to_char32((PCRE2_SPTR8)current->input, regtest_buf32, REGTEST_MAX_LENGTH32); + (void)pcre2_set_match_limit_32(mcontext32, 10000000); return_value32[1] = pcre2_match_32(re32, regtest_buf32, length32, - current->start_offset & OFFSET_MASK, current->match_options, mdata32_2, NULL); + current->start_offset & OFFSET_MASK, current->match_options, mdata32_2, mcontext32); if (pcre2_jit_compile_32(re32, jit_compile_mode)) { printf("\n32 bit: JIT compiler does not support \"%s\"\n", current->pattern); diff --git a/testdata/testinput15 b/testdata/testinput15 index cd12ad1..2ef6672 100644 --- a/testdata/testinput15 +++ b/testdata/testinput15 @@ -46,32 +46,45 @@ /(*LIMIT_DEPTH=4294967280)abc/I /(a+)*zz/ +\= Expect no match aaaaaaaaaaaaaz +\= Expect limit exceeded aaaaaaaaaaaaaz\=match_limit=3000 /(a+)*zz/ +\= Expect limit exceeded aaaaaaaaaaaaaz\=depth_limit=10 /(*LIMIT_MATCH=3000)(a+)*zz/I +\= Expect limit exceeded aaaaaaaaaaaaaz +\= Expect limit exceeded aaaaaaaaaaaaaz\=match_limit=60000 /(*LIMIT_MATCH=60000)(*LIMIT_MATCH=3000)(a+)*zz/I +\= Expect limit exceeded aaaaaaaaaaaaaz /(*LIMIT_MATCH=60000)(a+)*zz/I +\= Expect no match aaaaaaaaaaaaaz +\= Expect limit exceeded aaaaaaaaaaaaaz\=match_limit=3000 /(*LIMIT_DEPTH=10)(a+)*zz/I +\= Expect limit exceeded aaaaaaaaaaaaaz +\= Expect limit exceeded aaaaaaaaaaaaaz\=depth_limit=1000 /(*LIMIT_DEPTH=10)(*LIMIT_DEPTH=1000)(a+)*zz/I +\= Expect no match aaaaaaaaaaaaaz /(*LIMIT_DEPTH=1000)(a+)*zz/I +\= Expect no match aaaaaaaaaaaaaz +\= Expect limit exceeded aaaaaaaaaaaaaz\=depth_limit=10 # These three have infinitely nested recursions. diff --git a/testdata/testinput17 b/testdata/testinput17 index 9a73ef1..0944151 100644 --- a/testdata/testinput17 +++ b/testdata/testinput17 @@ -160,10 +160,13 @@ aaaaaaaaaaaaaz\=match_limit=3000 /(*LIMIT_MATCH=3000)(a+)*zz/I +\= Expect limit exceeded aaaaaaaaaaaaaz +\= Expect limit exceeded aaaaaaaaaaaaaz\=match_limit=60000 /(*LIMIT_MATCH=60000)(*LIMIT_MATCH=3000)(a+)*zz/I +\= Expect limit exceeded aaaaaaaaaaaaaz /(*LIMIT_MATCH=60000)(a+)*zz/I @@ -175,12 +178,15 @@ # These three have infinitely nested recursions. /((?2))((?1))/ +\= Expect JIT stack limit reached abc /((?(R2)a+|(?1)b))()/ +\= Expect JIT stack limit reached aaaabcde /(?(R)a*(?1)|((?R))b)/ +\= Expect JIT stack limit reached aaaabcde # Invalid options disable JIT when called via pcre2_match(), causing the @@ -277,7 +283,8 @@ /[axm]{7}/ /(.|.)*?bx/ - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabax +\= Expect limit exceeded + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabax\=match_limit=10000000 # Test JIT disable diff --git a/testdata/testinput6 b/testdata/testinput6 index 924bb48..f7dedb2 100644 --- a/testdata/testinput6 +++ b/testdata/testinput6 @@ -4938,6 +4938,7 @@ abcde\=aftertext /(*LIMIT_MATCH=100).*(?![|H]?.*(?![|H]?););.*(?![|H]?.*(?![|H]?););\x00\x00\x00\x00\x00\x00\x00(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?![|);)?.*(![|H]?);)?.*(?![|H]?);)?.*(?![|H]?);)?.*(?![|H]););![|H]?););[|H]?);|H]?);)\x00\x00\x00 \x00\x00\x00H]?););?![|H]?);)?.*(?![|H]?););[||H]?);)?.*(?![|H]?););[|H]?);(?![|H]?););![|H]?););[|H]?);|H]?);)?.*(?![|H]?););;[\x00\x00\x00\x00\x00\x00\x00![|H]?););![|H]?););[|H]?);|H]?);)?.*(?![|H]?););/no_dotstar_anchor +\= Expect limit exceeded .*(?![|H]?.*(?![|H]?););.*(?![|H]?.*(?![|H]?););\x00\x00\x00\x00\x00\x00\x00(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?![|);)?.*(![|H]?);)?.*(?![|H]?);)?.*(?![|H]?);)?.*(?![|H]););![|H]?););[|H]?);|H]?);)\x00\x00\x00 \x00\x00\x00H]?););?![|H]?);)?.*(?![|H]?););[||H]?);)?.*(?![|H]?););[|H]?);(?![|H]?););![|H]?););[|H]?);|H]?);)?.*(?![|H]?););;[\x00\x00\x00\x00\x00\x00\x00![|H]?););![|H]?););[|H]?);|H]?);)?.*(?![|H]?);); /\n/firstline diff --git a/testdata/testoutput15 b/testdata/testoutput15 index b2068d0..d09e781 100644 --- a/testdata/testoutput15 +++ b/testdata/testoutput15 @@ -124,12 +124,15 @@ Last code unit = 'c' Subject length lower bound = 3 /(a+)*zz/ +\= Expect no match aaaaaaaaaaaaaz No match +\= Expect limit exceeded aaaaaaaaaaaaaz\=match_limit=3000 Failed: error -47: match limit exceeded /(a+)*zz/ +\= Expect limit exceeded aaaaaaaaaaaaaz\=depth_limit=10 Failed: error -53: matching depth limit exceeded @@ -139,8 +142,10 @@ Match limit = 3000 Starting code units: a z Last code unit = 'z' Subject length lower bound = 2 +\= Expect limit exceeded aaaaaaaaaaaaaz Failed: error -47: match limit exceeded +\= Expect limit exceeded aaaaaaaaaaaaaz\=match_limit=60000 Failed: error -47: match limit exceeded @@ -150,6 +155,7 @@ Match limit = 3000 Starting code units: a z Last code unit = 'z' Subject length lower bound = 2 +\= Expect limit exceeded aaaaaaaaaaaaaz Failed: error -47: match limit exceeded @@ -159,8 +165,10 @@ Match limit = 60000 Starting code units: a z Last code unit = 'z' Subject length lower bound = 2 +\= Expect no match aaaaaaaaaaaaaz No match +\= Expect limit exceeded aaaaaaaaaaaaaz\=match_limit=3000 Failed: error -47: match limit exceeded @@ -170,8 +178,10 @@ Depth limit = 10 Starting code units: a z Last code unit = 'z' Subject length lower bound = 2 +\= Expect limit exceeded aaaaaaaaaaaaaz Failed: error -53: matching depth limit exceeded +\= Expect limit exceeded aaaaaaaaaaaaaz\=depth_limit=1000 Failed: error -53: matching depth limit exceeded @@ -181,6 +191,7 @@ Depth limit = 1000 Starting code units: a z Last code unit = 'z' Subject length lower bound = 2 +\= Expect no match aaaaaaaaaaaaaz No match @@ -190,8 +201,10 @@ Depth limit = 1000 Starting code units: a z Last code unit = 'z' Subject length lower bound = 2 +\= Expect no match aaaaaaaaaaaaaz No match +\= Expect limit exceeded aaaaaaaaaaaaaz\=depth_limit=10 Failed: error -53: matching depth limit exceeded diff --git a/testdata/testoutput17 b/testdata/testoutput17 index a0606a7..acf00e0 100644 --- a/testdata/testoutput17 +++ b/testdata/testoutput17 @@ -300,8 +300,10 @@ Starting code units: a z Last code unit = 'z' Subject length lower bound = 2 JIT compilation was successful +\= Expect limit exceeded aaaaaaaaaaaaaz Failed: error -47: match limit exceeded +\= Expect limit exceeded aaaaaaaaaaaaaz\=match_limit=60000 Failed: error -47: match limit exceeded @@ -312,6 +314,7 @@ Starting code units: a z Last code unit = 'z' Subject length lower bound = 2 JIT compilation was successful +\= Expect limit exceeded aaaaaaaaaaaaaz Failed: error -47: match limit exceeded @@ -332,14 +335,17 @@ Failed: error -47: match limit exceeded # These three have infinitely nested recursions. /((?2))((?1))/ +\= Expect JIT stack limit reached abc Failed: error -46: JIT stack limit reached /((?(R2)a+|(?1)b))()/ +\= Expect JIT stack limit reached aaaabcde Failed: error -46: JIT stack limit reached /(?(R)a*(?1)|((?R))b)/ +\= Expect JIT stack limit reached aaaabcde Failed: error -46: JIT stack limit reached @@ -516,7 +522,8 @@ Failed: error -46: JIT stack limit reached /[axm]{7}/ /(.|.)*?bx/ - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabax +\= Expect limit exceeded + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabax\=match_limit=10000000 Failed: error -47: match limit exceeded # Test JIT disable diff --git a/testdata/testoutput6 b/testdata/testoutput6 index c455af9..caec833 100644 --- a/testdata/testoutput6 +++ b/testdata/testoutput6 @@ -7761,6 +7761,7 @@ No match 0+ /(*LIMIT_MATCH=100).*(?![|H]?.*(?![|H]?););.*(?![|H]?.*(?![|H]?););\x00\x00\x00\x00\x00\x00\x00(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?![|);)?.*(![|H]?);)?.*(?![|H]?);)?.*(?![|H]?);)?.*(?![|H]););![|H]?););[|H]?);|H]?);)\x00\x00\x00 \x00\x00\x00H]?););?![|H]?);)?.*(?![|H]?););[||H]?);)?.*(?![|H]?););[|H]?);(?![|H]?););![|H]?););[|H]?);|H]?);)?.*(?![|H]?););;[\x00\x00\x00\x00\x00\x00\x00![|H]?););![|H]?););[|H]?);|H]?);)?.*(?![|H]?););/no_dotstar_anchor +\= Expect limit exceeded .*(?![|H]?.*(?![|H]?););.*(?![|H]?.*(?![|H]?););\x00\x00\x00\x00\x00\x00\x00(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?!(?![|);)?.*(![|H]?);)?.*(?![|H]?);)?.*(?![|H]?);)?.*(?![|H]););![|H]?););[|H]?);|H]?);)\x00\x00\x00 \x00\x00\x00H]?););?![|H]?);)?.*(?![|H]?););[||H]?);)?.*(?![|H]?););[|H]?);(?![|H]?););![|H]?););[|H]?);|H]?);)?.*(?![|H]?););;[\x00\x00\x00\x00\x00\x00\x00![|H]?););![|H]?););[|H]?);|H]?);)?.*(?![|H]?);); Failed: error -47: match limit exceeded