Skip to content

Commit

Permalink
Fixed bug #79821
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
twose committed Jul 10, 2020
1 parent a72c53a commit 150504e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ext/standard/tests/bug79821.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Bug #79821 (array grow during var_dump)
--FILE--
<?php

$foo = $bar = [];
for ($i = 0; $i < 3; $i++) {
$foo = [$foo, [&$bar]];
}
ob_start(function (string $buffer) use (&$bar) {
$bar[][] = null;
return '';
}, 1);
var_dump($foo[0]);
ob_end_clean();

echo "OK\n";

?>
--EXPECT--
OK
3 changes: 3 additions & 0 deletions ext/standard/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */
PUTS("*RECURSION*\n");
return;
}
GC_ADDREF(myht);
GC_PROTECT_RECURSION(myht);
}
count = zend_array_count(myht);
Expand Down Expand Up @@ -506,8 +507,10 @@ PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf) /* {{{ */
ZEND_HASH_FOREACH_KEY_VAL_IND(myht, index, key, val) {
php_array_element_export(val, index, key, level, buf);
} ZEND_HASH_FOREACH_END();

if (!(GC_FLAGS(myht) & GC_IMMUTABLE)) {
GC_UNPROTECT_RECURSION(myht);
GC_DELREF(myht);
}
if (level > 1) {
buffer_append_spaces(buf, level - 1);
Expand Down

0 comments on commit 150504e

Please sign in to comment.