1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/ext/json/tests/gh15168.phpt
Arnaud Le Blanc f3e87e2a6d Fix tests: Prevent stack overflow during dtor
On s390x the stack is smaller and/or the object dtor code uses more stack,
which causes the destruction of deeply nested objects to crash in these
tests. Here I ensure that objects are released one by one at the end of the
tests to avoid recursive dtor.

Closes GH-16561
Fixes GH-16528
2024-10-24 15:56:25 +02:00

43 lines
798 B
PHP

--TEST--
GH-15168 (stack overflow in json_encode())
--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 < 30000; $i++) {
$newNode = new Node();
$node->next = $newNode;
$node = $newNode;
}
var_dump(json_encode($firstNode, depth: 500000));
var_dump(json_last_error());
var_dump(json_last_error_msg());
while ($next = $firstNode->next) {
$firstNode->next = $next->next;
}
?>
--EXPECT--
bool(false)
int(1)
string(28) "Maximum stack depth exceeded"