Skip to content

Commit d97ce2f

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix GH-11374: Different preg_match result with -d pcre.jit=0
2 parents c19347a + e7cbcfd commit d97ce2f

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

ext/pcre/pcre2lib/pcre2_match.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5847,7 +5847,7 @@ fprintf(stderr, "++ op=%d\n", *Fecode);
58475847
{
58485848
P = (heapframe *)((char *)N - frame_size);
58495849
memcpy((char *)F + offsetof(heapframe, ovector), P->ovector,
5850-
P->offset_top * sizeof(PCRE2_SIZE));
5850+
Foffset_top * sizeof(PCRE2_SIZE));
58515851
Foffset_top = P->offset_top;
58525852
Fcapture_last = P->capture_last;
58535853
Fcurrent_recurse = P->current_recurse;

ext/pcre/tests/gh11374.phpt

Lines changed: 60 additions & 0 deletions
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+
)

0 commit comments

Comments
 (0)