Skip to content

Commit d188ca7

Browse files
committed
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>
1 parent a5cef84 commit d188ca7

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

ext/pcre/php_pcre.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,11 @@ static zend_always_inline size_t calculate_unit_length(pcre_cache_entry *pce, co
595595
PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, int locale_aware)
596596
{
597597
pcre2_code *re = NULL;
598+
#if 10 == PCRE2_MAJOR && 37 == PCRE2_MINOR
599+
uint32_t coptions = PCRE2_NO_START_OPTIMIZE;
600+
#else
598601
uint32_t coptions = 0;
602+
#endif
599603
PCRE2_UCHAR error[128];
600604
PCRE2_SIZE erroffset;
601605
int errnumber;

ext/pcre/tests/bug75539.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
--TEST--
22
Bug #75539 - Recursive call errors are not reported by preg_last_error()
3+
--SKIPIF--
4+
<?php
5+
if (10 == PCRE_VERSION_MAJOR && 37 == PCRE_VERSION_MINOR) {
6+
die("skip ");
7+
}
8+
?>
39
--FILE--
410
<?php
511

ext/pcre/tests/bug81101.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Bug #81101 - Invalid single character repetition issues in JIT
3+
--FILE--
4+
<?php
5+
6+
$matches = [];
7+
$test = ' App\Domain\Repository\MetaData\SomethingRepositoryInterface';
8+
9+
preg_match('/\\\\([^\\\\]+)\s*$/', $test, $matches);
10+
var_dump($matches);
11+
12+
$test2 = ' App\Domain\Exception\NotFoundException';
13+
14+
preg_match('/\\\\([^\\\\]+)\s*$/', $test2, $matches);
15+
var_dump($matches);
16+
17+
?>
18+
--EXPECT--
19+
array(2) {
20+
[0]=>
21+
string(29) "\SomethingRepositoryInterface"
22+
[1]=>
23+
string(28) "SomethingRepositoryInterface"
24+
}
25+
array(2) {
26+
[0]=>
27+
string(18) "\NotFoundException"
28+
[1]=>
29+
string(17) "NotFoundException"
30+
}

0 commit comments

Comments
 (0)