diff --git a/NEWS b/NEWS index d32f0ab6f52..96dd60f1f8b 100644 --- a/NEWS +++ b/NEWS @@ -31,6 +31,10 @@ PHP NEWS . Fixed bug GH-12489 (Missing sigbio creation checking in openssl_cms_verify). (Jakub Zelenka) +- PCRE: + . Fixed bug GH-11374 (Backport upstream fix, Different preg_match result + with -d pcre.jit=0). (mvorisek) + - Random: . Fix Randomizer::getFloat() returning incorrect results under certain circumstances. (timwolla) diff --git a/ext/pcre/pcre2lib/pcre2_match.c b/ext/pcre/pcre2lib/pcre2_match.c index 168b9fad019..33bb345bba3 100644 --- a/ext/pcre/pcre2lib/pcre2_match.c +++ b/ext/pcre/pcre2lib/pcre2_match.c @@ -5847,7 +5847,7 @@ fprintf(stderr, "++ op=%d\n", *Fecode); { P = (heapframe *)((char *)N - frame_size); memcpy((char *)F + offsetof(heapframe, ovector), P->ovector, - P->offset_top * sizeof(PCRE2_SIZE)); + Foffset_top * sizeof(PCRE2_SIZE)); Foffset_top = P->offset_top; Fcapture_last = P->capture_last; Fcurrent_recurse = P->current_recurse; diff --git a/ext/pcre/tests/gh11374.phpt b/ext/pcre/tests/gh11374.phpt new file mode 100644 index 00000000000..07f8f4bccfd --- /dev/null +++ b/ext/pcre/tests/gh11374.phpt @@ -0,0 +1,60 @@ +--TEST-- +GH-11374 (PCRE regular expression without JIT enabled gives different result) +--FILE-- + + (?: + (?:\{ (?&types) \}) + | (a) + ) + (\*?) + ) +'; + +ini_set('pcre.jit', '0'); +$res = preg_match('{^' . $regex . '$}x', '{a}', $matches, PREG_OFFSET_CAPTURE); +ini_set('pcre.jit', '1'); +// regex must be different to prevent regex cache, so just add 2nd "x" modifier +$res2 = preg_match('{^' . $regex . '$}xx', '{a}', $matches2, PREG_OFFSET_CAPTURE); + +var_dump($matches === $matches2); +print_r($matches); + +?> +--EXPECT-- +bool(true) +Array +( + [0] => Array + ( + [0] => {a} + [1] => 0 + ) + + [types] => Array + ( + [0] => {a} + [1] => 0 + ) + + [1] => Array + ( + [0] => {a} + [1] => 0 + ) + + [2] => Array + ( + [0] => + [1] => -1 + ) + + [3] => Array + ( + [0] => + [1] => 3 + ) + +)