Skip to content

Commit 17d46bb

Browse files
authored
Fix oss-fuzz #71382 (#15854)
The return value of zho_build_properties_ex() is passed to ZVAL_ARR(), which sets the IS_TYPE_REFCOUNTED flag. Returning &zend_emtpy_array will crash later when trying to dtor the zval. I'm fixing this by returning zend_new_array(0) instead of &zend_empty_array. An alternative was to make ZVAL_ARR() aware of immutable arrays, like ZVAL_STR() is with interned strings, but I found no other problematic cases.
1 parent 1ce8652 commit 17d46bb

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
oss-fuzz #71382
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public $a;
8+
public $b {
9+
get {
10+
}
11+
}
12+
}
13+
14+
$reflector = new ReflectionClass(C::class);
15+
$obj = $reflector->newLazyGhost(function() {
16+
throw new \Exception('initializer');
17+
});
18+
19+
try {
20+
foreach($obj as $a) {
21+
}
22+
} catch (Exception $e) {
23+
printf("%s: %s\n", $e::class, $e->getMessage());
24+
}
25+
26+
--EXPECT--
27+
Exception: initializer

Zend/zend_property_hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static zend_array *zho_build_properties_ex(zend_object *zobj, bool check_access,
5454
if (UNEXPECTED(zend_lazy_object_must_init(zobj))) {
5555
zobj = zend_lazy_object_init(zobj);
5656
if (UNEXPECTED(!zobj)) {
57-
return (zend_array*) &zend_empty_array;
57+
return zend_new_array(0);
5858
}
5959
}
6060

0 commit comments

Comments
 (0)