From 466fc78d2c373eae6acad4bd5a4553c5c0d1d18b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Thu, 8 Jun 2023 23:25:41 +0200 Subject: [PATCH] Mangle PCRE regex cache key with JIT option Closes GH-11396 --- NEWS | 2 ++ ext/pcre/php_pcre.c | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 5134a77d83f..1dd5bdcef13 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,8 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 8.1.22 +- PCRE: + . Mangle PCRE regex cache key with JIT option. (mvorisek) 06 Jul 2023, PHP 8.1.21 diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 6249a807970..1716871d7f5 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -627,11 +627,24 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in pcre_cache_entry *ret; if (locale_aware && BG(ctype_string)) { - key = zend_string_concat2( + key = zend_string_concat3( ZSTR_VAL(BG(ctype_string)), ZSTR_LEN(BG(ctype_string)), - ZSTR_VAL(regex), ZSTR_LEN(regex)); + ZSTR_VAL(regex), ZSTR_LEN(regex), +#ifdef HAVE_PCRE_JIT_SUPPORT + PCRE_G(jit) ? "1" : "0", 1 +#else + "", 0 +#endif + ); } else { +#ifdef HAVE_PCRE_JIT_SUPPORT + key = zend_string_concat2( + ZSTR_VAL(regex), ZSTR_LEN(regex), + PCRE_G(jit) ? "1" : "0", 1 + ); +#else key = regex; +#endif } /* Try to lookup the cached regex entry, and if successful, just pass @@ -786,7 +799,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in return NULL; } - if (key != regex) { + if (locale_aware && BG(ctype_string)) { tables = (uint8_t *)zend_hash_find_ptr(&char_tables, BG(ctype_string)); if (!tables) { zend_string *_k;