Skip to content

Commit 150504e

Browse files
committed
Fixed bug #79821
HashTable was reallocated (zend_hash_packed_grow) during php_var_dump, so we should call GC_ADDREF to make SEPARATE_ARRAY work. Closes GH-5837.
1 parent a72c53a commit 150504e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

ext/standard/tests/bug79821.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug #79821 (array grow during var_dump)
3+
--FILE--
4+
<?php
5+
6+
$foo = $bar = [];
7+
for ($i = 0; $i < 3; $i++) {
8+
$foo = [$foo, [&$bar]];
9+
}
10+
ob_start(function (string $buffer) use (&$bar) {
11+
$bar[][] = null;
12+
return '';
13+
}, 1);
14+
var_dump($foo[0]);
15+
ob_end_clean();
16+
17+
echo "OK\n";
18+
19+
?>
20+
--EXPECT--
21+
OK

ext/standard/var.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */
122122
PUTS("*RECURSION*\n");
123123
return;
124124
}
125+
GC_ADDREF(myht);
125126
GC_PROTECT_RECURSION(myht);
126127
}
127128
count = zend_array_count(myht);
@@ -506,8 +507,10 @@ PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf) /* {{{ */
506507
ZEND_HASH_FOREACH_KEY_VAL_IND(myht, index, key, val) {
507508
php_array_element_export(val, index, key, level, buf);
508509
} ZEND_HASH_FOREACH_END();
510+
509511
if (!(GC_FLAGS(myht) & GC_IMMUTABLE)) {
510512
GC_UNPROTECT_RECURSION(myht);
513+
GC_DELREF(myht);
511514
}
512515
if (level > 1) {
513516
buffer_append_spaces(buf, level - 1);

0 commit comments

Comments
 (0)