Skip to content

Commit bff2743

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Fixed bug #78379 (Cast to object confuses GC, causes crash)
2 parents 9ea39d1 + 358379b commit bff2743

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ PHP NEWS
44

55
- Core:
66
. Fixed bug #78363 (Buffer overflow in zendparse). (Nikita)
7+
. Fixed bug #78379 (Cast to object confuses GC, causes crash). (Dmitry)
78

89
- Curl:
910
. Fixed bug #77946 (Bad cURL resources returned by curl_multi_info_read()).

Zend/tests/bug78379.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
Bug #78379 (Cast to object confuses GC, causes crash)
3+
--INI--
4+
opcache.enable=0
5+
--FILE--
6+
<?php
7+
class C {
8+
public function __construct() {
9+
$this->p = (object)["x" => [1]];
10+
}
11+
}
12+
class E {
13+
}
14+
$e = new E;
15+
$e->f = new E;
16+
$e->f->e = $e;
17+
$e->a = new C;
18+
$e = null;
19+
gc_collect_cycles();
20+
var_dump(new C);
21+
?>
22+
--EXPECTF--
23+
object(C)#%d (1) {
24+
["p"]=>
25+
object(stdClass)#%d (1) {
26+
["x"]=>
27+
array(1) {
28+
[0]=>
29+
int(1)
30+
}
31+
}
32+
}

Zend/zend_object_handlers.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ ZEND_API HashTable *zend_std_get_gc(zval *object, zval **table, int *n) /* {{{ *
124124
if (zobj->properties) {
125125
*table = NULL;
126126
*n = 0;
127+
if (UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)
128+
&& EXPECTED(!(GC_FLAGS(zobj->properties) & IS_ARRAY_IMMUTABLE))) {
129+
GC_DELREF(zobj->properties);
130+
zobj->properties = zend_array_dup(zobj->properties);
131+
}
127132
return zobj->properties;
128133
} else {
129134
*table = zobj->properties_table;

0 commit comments

Comments
 (0)