Skip to content

Commit 720438c

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fixed bug #78379 (Cast to object confuses GC, causes crash)
2 parents be79489 + bff2743 commit 720438c

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
@@ -11,6 +11,7 @@ PHP NEWS
1111
. Fixed bug #78344 (Segmentation fault on zend_check_protected). (Nikita)
1212
. Fixed bug #78356 (Array returned from ArrayAccess is incorrectly unpacked
1313
as argument). (Nikita)
14+
. Fixed bug #78379 (Cast to object confuses GC, causes crash). (Dmitry)
1415

1516
- Exif:
1617
. Fixed bug #78333 (Exif crash (bus error) due to wrong alignment and

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
@@ -127,6 +127,11 @@ ZEND_API HashTable *zend_std_get_gc(zval *object, zval **table, int *n) /* {{{ *
127127
if (zobj->properties) {
128128
*table = NULL;
129129
*n = 0;
130+
if (UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)
131+
&& EXPECTED(!(GC_FLAGS(zobj->properties) & IS_ARRAY_IMMUTABLE))) {
132+
GC_DELREF(zobj->properties);
133+
zobj->properties = zend_array_dup(zobj->properties);
134+
}
130135
return zobj->properties;
131136
} else {
132137
*table = zobj->properties_table;

0 commit comments

Comments
 (0)