Skip to content

Commit 6d458ca

Browse files
committed
Fix prop info fetching from prop slot with added hooks
Fixes GH-18268 Closes GH-18271
1 parent 1e9e397 commit 6d458ca

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ PHP NEWS
77
evaluation). (ilutov)
88
. Fixed bug GH-18038 (Lazy proxy calls magic methods twice). (Arnaud)
99
. Fixed bug GH-18209 (Use-after-free in extract() with EXTR_REFS). (ilutov)
10+
. Fixed bug GH-18268 (Segfault in array_walk() on object with added property
11+
hooks). (ilutov)
1012

1113
- DBA:
1214
. FIxed bug GH-18247 dba_popen() memory leak on invalid path. (David Carlier)
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
GH-18268: array_walk() on object with added property hooks
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
public $prop = 42;
8+
}
9+
10+
class B extends A {
11+
public $prop = 42 {
12+
set {}
13+
}
14+
}
15+
16+
$b = new B;
17+
array_walk($b, function (&$item) {
18+
var_dump($item);
19+
});
20+
21+
?>
22+
--EXPECT--
23+
int(42)

Zend/zend_compile.h

+2
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,8 @@ typedef struct _zend_property_info {
464464
((uint32_t)(XtOffsetOf(zend_object, properties_table) + sizeof(zval) * (num)))
465465
#define OBJ_PROP_TO_NUM(offset) \
466466
(((offset) - OBJ_PROP_TO_OFFSET(0)) / sizeof(zval))
467+
#define OBJ_PROP_SLOT_TO_OFFSET(obj, slot) \
468+
((uintptr_t)(slot) - (uintptr_t)(obj))
467469

468470
typedef struct _zend_class_constant {
469471
zval value; /* flags are stored in u2 */

Zend/zend_objects_API.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ ZEND_API void ZEND_FASTCALL zend_objects_store_del(zend_object *object) /* {{{ *
203203

204204
ZEND_API ZEND_COLD zend_property_info *zend_get_property_info_for_slot_slow(zend_object *obj, zval *slot)
205205
{
206-
uintptr_t offset = (uintptr_t)slot - (uintptr_t)obj->properties_table;
206+
uintptr_t offset = OBJ_PROP_SLOT_TO_OFFSET(obj, slot);
207207
zend_property_info *prop_info;
208208
ZEND_HASH_MAP_FOREACH_PTR(&obj->ce->properties_info, prop_info) {
209209
if (prop_info->offset == offset) {

0 commit comments

Comments
 (0)