Skip to content

Commit 83a505e

Browse files
mvoriseknielsdos
authored andcommittedOct 27, 2023
Fix GH-11374: Different preg_match result with -d pcre.jit=0
This is a backport of PCRE2Project/pcre2#300. Closes GH-12439.
1 parent 5f46d86 commit 83a505e

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed
 

‎NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ PHP NEWS
2626
. Fixed bug GH-12489 (Missing sigbio creation checking in openssl_cms_verify).
2727
(Jakub Zelenka)
2828

29+
- PCRE:
30+
. Fixed bug GH-11374 (Backport upstream fix, Different preg_match result
31+
with -d pcre.jit=0). (mvorisek)
32+
2933
- SOAP:
3034
. Fixed bug GH-12392 (Segmentation fault on SoapClient::__getTypes).
3135
(nielsdos)

‎ext/pcre/pcre2lib/pcre2_match.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5640,7 +5640,7 @@ fprintf(stderr, "++ op=%d\n", *Fecode);
56405640
{
56415641
P = (heapframe *)((char *)N - frame_size);
56425642
memcpy((char *)F + offsetof(heapframe, ovector), P->ovector,
5643-
P->offset_top * sizeof(PCRE2_SIZE));
5643+
Foffset_top * sizeof(PCRE2_SIZE));
56445644
Foffset_top = P->offset_top;
56455645
Fcapture_last = P->capture_last;
56465646
Fcurrent_recurse = P->current_recurse;

‎ext/pcre/tests/gh11374.phpt

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
--TEST--
2+
GH-11374 (PCRE regular expression without JIT enabled gives different result)
3+
--FILE--
4+
<?php
5+
6+
$regex = '
7+
(?<types>
8+
(?:
9+
(?:\{ (?&types) \})
10+
| (a)
11+
)
12+
(\*?)
13+
)
14+
';
15+
16+
ini_set('pcre.jit', '0');
17+
$res = preg_match('{^' . $regex . '$}x', '{a}', $matches, PREG_OFFSET_CAPTURE);
18+
ini_set('pcre.jit', '1');
19+
// regex must be different to prevent regex cache, so just add 2nd "x" modifier
20+
$res2 = preg_match('{^' . $regex . '$}xx', '{a}', $matches2, PREG_OFFSET_CAPTURE);
21+
22+
var_dump($matches === $matches2);
23+
print_r($matches);
24+
25+
?>
26+
--EXPECT--
27+
bool(true)
28+
Array
29+
(
30+
[0] => Array
31+
(
32+
[0] => {a}
33+
[1] => 0
34+
)
35+
36+
[types] => Array
37+
(
38+
[0] => {a}
39+
[1] => 0
40+
)
41+
42+
[1] => Array
43+
(
44+
[0] => {a}
45+
[1] => 0
46+
)
47+
48+
[2] => Array
49+
(
50+
[0] =>
51+
[1] => -1
52+
)
53+
54+
[3] => Array
55+
(
56+
[0] =>
57+
[1] => 3
58+
)
59+
60+
)

1 commit comments

Comments
 (1)

andypost commented on Nov 8, 2023

@andypost
Contributor

Filed report #12628

Please sign in to comment.