Skip to content

Commit fced34e

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix incorrect zval type_flags in preg_replace_callback_array() for immutable arrays
2 parents ba33bbe + d1fc88c commit fced34e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

ext/pcre/php_pcre.c

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

24402440
if (subject_ht) {
2441-
RETURN_ARR(subject_ht);
2441+
RETVAL_ARR(subject_ht);
2442+
// Unset the type_flags of immutable arrays to prevent the VM from performing refcounting
2443+
if (GC_FLAGS(subject_ht) & IS_ARRAY_IMMUTABLE) {
2444+
Z_TYPE_FLAGS_P(return_value) = 0;
2445+
}
2446+
return;
24422447
} else {
24432448
RETURN_STR(subject_str);
24442449
}

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)