Skip to content

Commit 40efb7a

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fixed bug #79830 introduced by fixing bug #79821 # Conflicts: # ext/standard/var.c
2 parents 342fe09 + 6ef08b1 commit 40efb7a

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

ext/standard/tests/bug79821.phpt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ Bug #79821 (array grow during var_dump)
33
--FILE--
44
<?php
55

6-
$foo = $bar = [];
7-
for ($i = 0; $i < 3; $i++) {
8-
$foo = [$foo, [&$bar]];
6+
foreach (['var_dump', 'debug_zval_dump', 'var_export'] as $output) {
7+
$foo = $bar = [];
8+
for ($i = 0; $i < 3; $i++) {
9+
$foo = [$foo, [&$bar]];
10+
}
11+
ob_start(function (string $buffer) use (&$bar) {
12+
$bar[][] = null;
13+
return '';
14+
}, 64);
15+
$output($foo[0]);
16+
ob_end_clean();
917
}
10-
ob_start(function (string $buffer) use (&$bar) {
11-
$bar[][] = null;
12-
return '';
13-
}, 1);
14-
var_dump($foo[0]);
15-
ob_end_clean();
1618

1719
echo "OK\n";
1820

ext/standard/var.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */
132132
}
133133
count = zend_array_count(myht);
134134
php_printf("%sarray(%d) {\n", COMMON, count);
135-
136135
ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) {
137136
php_array_element_dump(val, num, key, level);
138137
} ZEND_HASH_FOREACH_END();
139138
if (!(GC_FLAGS(myht) & GC_IMMUTABLE)) {
140139
GC_UNPROTECT_RECURSION(myht);
140+
GC_DELREF(myht);
141141
}
142142
if (level > 1) {
143143
php_printf("%*c", level-1, ' ');
@@ -303,20 +303,26 @@ PHPAPI void php_debug_zval_dump(zval *struc, int level) /* {{{ */
303303
break;
304304
case IS_ARRAY:
305305
myht = Z_ARRVAL_P(struc);
306-
if (level > 1 && !(GC_FLAGS(myht) & GC_IMMUTABLE)) {
307-
if (GC_IS_RECURSIVE(myht)) {
308-
PUTS("*RECURSION*\n");
309-
return;
306+
if (!(GC_FLAGS(myht) & GC_IMMUTABLE)) {
307+
if (level > 1) {
308+
if (GC_IS_RECURSIVE(myht)) {
309+
PUTS("*RECURSION*\n");
310+
return;
311+
}
312+
GC_PROTECT_RECURSION(myht);
310313
}
311-
GC_PROTECT_RECURSION(myht);
314+
GC_ADDREF(myht);
312315
}
313316
count = zend_array_count(myht);
314317
php_printf("%sarray(%d) refcount(%u){\n", COMMON, count, Z_REFCOUNTED_P(struc) ? Z_REFCOUNT_P(struc) : 1);
315318
ZEND_HASH_FOREACH_KEY_VAL_IND(myht, index, key, val) {
316319
zval_array_element_dump(val, index, key, level);
317320
} ZEND_HASH_FOREACH_END();
318-
if (level > 1 && !(GC_FLAGS(myht) & GC_IMMUTABLE)) {
319-
GC_UNPROTECT_RECURSION(myht);
321+
if (!(GC_FLAGS(myht) & GC_IMMUTABLE)) {
322+
if (level > 1) {
323+
GC_UNPROTECT_RECURSION(myht);
324+
}
325+
GC_DELREF(myht);
320326
}
321327
if (level > 1) {
322328
php_printf("%*c", level - 1, ' ');
@@ -519,6 +525,7 @@ PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf) /* {{{ */
519525
zend_error(E_WARNING, "var_export does not handle circular references");
520526
return;
521527
}
528+
GC_ADDREF(myht);
522529
GC_PROTECT_RECURSION(myht);
523530
}
524531
if (level > 1) {
@@ -529,7 +536,6 @@ PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf) /* {{{ */
529536
ZEND_HASH_FOREACH_KEY_VAL_IND(myht, index, key, val) {
530537
php_array_element_export(val, index, key, level, buf);
531538
} ZEND_HASH_FOREACH_END();
532-
533539
if (!(GC_FLAGS(myht) & GC_IMMUTABLE)) {
534540
GC_UNPROTECT_RECURSION(myht);
535541
GC_DELREF(myht);

0 commit comments

Comments
 (0)