mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Fix GH-20840: crash on nested object with var_dump().
mitigate it with stack check limit. close GH-20843
This commit is contained in:
2
NEWS
2
NEWS
@@ -13,6 +13,8 @@ PHP NEWS
|
||||
- Standard:
|
||||
. Fixed bug #74357 (lchown fails to change ownership of symlink with ZTS)
|
||||
(Jakub Zelenka)
|
||||
. Fixed bug GH-20843 (var_dump() crash with nested objects)
|
||||
(David Carlier)
|
||||
|
||||
15 Jan 2026, PHP 8.4.17
|
||||
|
||||
|
||||
38
ext/standard/tests/general_functions/gh20840.phpt
Normal file
38
ext/standard/tests/general_functions/gh20840.phpt
Normal file
@@ -0,0 +1,38 @@
|
||||
--TEST--
|
||||
GH-20840 (var_dump() crash with nested objects)
|
||||
--CREDITS--
|
||||
bendrissou
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (ini_get('zend.max_allowed_stack_size') === false) {
|
||||
die('skip No stack limit support');
|
||||
}
|
||||
if (getenv('SKIP_ASAN')) {
|
||||
die('skip ASAN needs different stack limit setting due to more stack space usage');
|
||||
}
|
||||
?>
|
||||
--INI--
|
||||
zend.max_allowed_stack_size=512K
|
||||
--FILE--
|
||||
<?php
|
||||
class Node {
|
||||
public $next;
|
||||
}
|
||||
|
||||
$firstNode = new Node();
|
||||
$node = $firstNode;
|
||||
|
||||
for ($i = 0; $i < 50000; $i++) {
|
||||
$newNode = new Node();
|
||||
$node->next = $newNode;
|
||||
$node = $newNode;
|
||||
}
|
||||
|
||||
var_dump($firstNode);
|
||||
|
||||
while ($next = $firstNode->next) {
|
||||
$firstNode->next = $next->next;
|
||||
}
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
^object\(Node\)#\d+ \(\d+\).*(nesting level too deep|["\s}]*)$
|
||||
@@ -56,6 +56,12 @@ static void php_object_property_dump(zend_property_info *prop_info, zval *zv, ze
|
||||
{
|
||||
const char *prop_name, *class_name;
|
||||
|
||||
#ifdef ZEND_CHECK_STACK_LIMIT
|
||||
if (UNEXPECTED(zend_call_stack_overflowed(EG(stack_limit)))) {
|
||||
php_printf("%*cnesting level too deep", level + 1, ' ');
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (key == NULL) { /* numeric key */
|
||||
php_printf("%*c[" ZEND_LONG_FMT "]=>\n", level + 1, ' ', index);
|
||||
} else { /* string key */
|
||||
|
||||
Reference in New Issue
Block a user