pcre: Workaround bug #81101

The way to fix it is to disable certain match start optimizaions. The
observed performance impact appears negligible ATM, compared to the
functional regression revealed.

A possible side effect might occur if a pattern uses (*COMMIT) or
(*MARK), which is however not a very broadly used syntax in PHP. Still
this should be observed and handled by possibly adding a possibility to
reverse PCRE2_NO_START_OPTIMIZE on the user side.

One test shows a behavior change, where instead of int 0 the match
would produce an error and return false. Except strict comparison
is used, this should be acceptable.

Signed-off-by: Anatol Belski <ab@php.net>
(cherry picked from commit d188ca7688)
Signed-off-by: Anatol Belski <ab@php.net>
This commit is contained in:
Anatol Belski 2021-06-06 17:46:59 +02:00
parent bc59b046c6
commit 1a1d86d562
3 changed files with 40 additions and 0 deletions

View file

@ -570,7 +570,11 @@ static zend_always_inline size_t calculate_unit_length(pcre_cache_entry *pce, ch
PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, int locale_aware)
{
pcre2_code *re = NULL;
#if 10 == PCRE2_MAJOR && 37 == PCRE2_MINOR
uint32_t coptions = PCRE2_NO_START_OPTIMIZE;
#else
uint32_t coptions = 0;
#endif
uint32_t extra_coptions = PHP_PCRE_DEFAULT_EXTRA_COPTIONS;
PCRE2_UCHAR error[128];
PCRE2_SIZE erroffset;