Fix GH-11374: Different preg_match result with -d pcre.jit=0

This is a backport of https://github.com/PCRE2Project/pcre2/pull/300.

Closes GH-12439.
This commit is contained in:
Michael Voříšek 2023-10-14 23:48:00 +02:00 committed by Niels Dossche
parent 5f46d86955
commit 83a505e85f
3 changed files with 65 additions and 1 deletions

4
NEWS
View file

@ -26,6 +26,10 @@ PHP NEWS
. Fixed bug GH-12489 (Missing sigbio creation checking in openssl_cms_verify). . Fixed bug GH-12489 (Missing sigbio creation checking in openssl_cms_verify).
(Jakub Zelenka) (Jakub Zelenka)
- PCRE:
. Fixed bug GH-11374 (Backport upstream fix, Different preg_match result
with -d pcre.jit=0). (mvorisek)
- SOAP: - SOAP:
. Fixed bug GH-12392 (Segmentation fault on SoapClient::__getTypes). . Fixed bug GH-12392 (Segmentation fault on SoapClient::__getTypes).
(nielsdos) (nielsdos)

View file

@ -5640,7 +5640,7 @@ fprintf(stderr, "++ op=%d\n", *Fecode);
{ {
P = (heapframe *)((char *)N - frame_size); P = (heapframe *)((char *)N - frame_size);
memcpy((char *)F + offsetof(heapframe, ovector), P->ovector, memcpy((char *)F + offsetof(heapframe, ovector), P->ovector,
P->offset_top * sizeof(PCRE2_SIZE)); Foffset_top * sizeof(PCRE2_SIZE));
Foffset_top = P->offset_top; Foffset_top = P->offset_top;
Fcapture_last = P->capture_last; Fcapture_last = P->capture_last;
Fcurrent_recurse = P->current_recurse; Fcurrent_recurse = P->current_recurse;

View file

@ -0,0 +1,60 @@
--TEST--
GH-11374 (PCRE regular expression without JIT enabled gives different result)
--FILE--
<?php
$regex = '
(?<types>
(?:
(?:\{ (?&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
)
)