Skip to content

Commit d1fc88c

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix incorrect zval type_flags in preg_replace_callback_array() for immutable arrays
2 parents ed80a7e + 66ce205 commit d1fc88c

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ PHP NEWS
99
. Fixed bug #80602 (Segfault when using DOMChildNode::before()).
1010
(Nathan Freeman)
1111

12+
- PCRE:
13+
. Fixed bug GH-10968 (Segfault in preg_replace_callback_array()). (ilutov)
14+
1215
- SPL:
1316
. Handle indirect zvals and use up-to-date properties in
1417
SplFixedArray::__serialize. (nielsdos)

ext/pcre/php_pcre.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2457,7 +2457,12 @@ PHP_FUNCTION(preg_replace_callback_array)
24572457
}
24582458

24592459
if (subject_ht) {
2460-
RETURN_ARR(subject_ht);
2460+
RETVAL_ARR(subject_ht);
2461+
// Unset the type_flags of immutable arrays to prevent the VM from performing refcounting
2462+
if (GC_FLAGS(subject_ht) & IS_ARRAY_IMMUTABLE) {
2463+
Z_TYPE_FLAGS_P(return_value) = 0;
2464+
}
2465+
return;
24612466
} else {
24622467
RETURN_STR(subject_str);
24632468
}

ext/pcre/tests/gh10968.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
GH-10968: preg_replace_callback_array() segmentation fault
3+
--FILE--
4+
<?php
5+
var_dump(preg_replace_callback_array([], []));
6+
var_dump(preg_replace_callback_array([], ''));
7+
?>
8+
--EXPECT--
9+
array(0) {
10+
}
11+
string(0) ""

0 commit comments

Comments
 (0)