Skip to content

Commit 1ea8a10

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix phpGH-11374: Different preg_match result with -d pcre.jit=0
2 parents 770c1b0 + 83a505e commit 1ea8a10

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
@@ -29,6 +29,10 @@ PHP NEWS
2929
. Fixed bug GH-12489 (Missing sigbio creation checking in openssl_cms_verify).
3030
(Jakub Zelenka)
3131

32+
- PCRE:
33+
. Fixed bug GH-11374 (Backport upstream fix, Different preg_match result
34+
with -d pcre.jit=0). (mvorisek)
35+
3236
- SOAP:
3337
. Fixed bug GH-12392 (Segmentation fault on SoapClient::__getTypes).
3438
(nielsdos)

ext/pcre/pcre2lib/pcre2_match.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5833,7 +5833,7 @@ fprintf(stderr, "++ op=%d\n", *Fecode);
58335833
{
58345834
P = (heapframe *)((char *)N - frame_size);
58355835
memcpy((char *)F + offsetof(heapframe, ovector), P->ovector,
5836-
P->offset_top * sizeof(PCRE2_SIZE));
5836+
Foffset_top * sizeof(PCRE2_SIZE));
58375837
Foffset_top = P->offset_top;
58385838
Fcapture_last = P->capture_last;
58395839
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+
)

0 commit comments

Comments
 (0)