Skip to content

Commit 81e50b4

Browse files
committed
Fix GH-11178: Segmentation fault in spl_array_it_get_current_data (PHP 8.1.18)
Dynamic property case in zend_get_property_info() can return NULL for prop info. This was not handled. Closes GH-11182.
1 parent d75c1d0 commit 81e50b4

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ PHP NEWS
1313
- PGSQL:
1414
. Fixed parameter parsing of pg_lo_export(). (kocsismate)
1515

16+
- SPL:
17+
. Fixed bug GH-11178 (Segmentation fault in spl_array_it_get_current_data
18+
(PHP 8.1.18)). (nielsdos)
19+
1620
- Standard:
1721
. Fixed bug GH-11138 (move_uploaded_file() emits open_basedir warning for
1822
source file). (ilutov)

ext/spl/spl_array.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,8 @@ static zval *spl_array_it_get_current_data(zend_object_iterator *iter) /* {{{ */
10371037
zend_hash_get_current_key_ex(aht, &key, NULL, spl_array_get_pos_ptr(aht, object));
10381038
zend_class_entry *ce = Z_OBJCE(object->array);
10391039
zend_property_info *prop_info = zend_get_property_info(ce, key, true);
1040-
if (ZEND_TYPE_IS_SET(prop_info->type)) {
1040+
ZEND_ASSERT(prop_info != ZEND_WRONG_PROPERTY_INFO);
1041+
if (EXPECTED(prop_info != NULL) && ZEND_TYPE_IS_SET(prop_info->type)) {
10411042
if (prop_info->flags & ZEND_ACC_READONLY) {
10421043
zend_throw_error(NULL,
10431044
"Cannot acquire reference to readonly property %s::$%s",

ext/spl/tests/gh11178.phpt

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
GH-11178 (Segmentation fault in spl_array_it_get_current_data (PHP 8.1.18))
3+
--FILE--
4+
<?php
5+
#[AllowDynamicProperties]
6+
class A implements IteratorAggregate {
7+
function __construct() {
8+
$this->{'x'} = 1;
9+
}
10+
11+
function getIterator(): Traversable {
12+
return new ArrayIterator($this);
13+
}
14+
}
15+
16+
$obj = new A;
17+
18+
foreach ($obj as $k => &$v) {
19+
$v = 3;
20+
}
21+
22+
var_dump($obj);
23+
?>
24+
--EXPECT--
25+
object(A)#1 (1) {
26+
["x"]=>
27+
&int(3)
28+
}

0 commit comments

Comments
 (0)