-
Notifications
You must be signed in to change notification settings - Fork 7.8k
stack overflow in json_encode() #15168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
can be reproduced with php 8.2 |
Related / similar: #15169 |
I don't know how that can help you, but I reproduce both bugs in PHP v7
Here is illustrating my point : <?php
class Node
{
/** @var Node */
public $previous;
/** @var Node */
public $next;
}
$firstNode = new Node();
$firstNode->previous = $firstNode;
$firstNode->next = $firstNode;
$circularDoublyLinkedList = $firstNode;
$ser = serialize($circularDoublyLinkedList);
$jser = json_encode($circularDoublyLinkedList);
var_dump($jser); //bool(false)
var_dump($ser); //string(49) "O:4:"Node":2:{s:8:"previous";r:1;s:4:"next";r:1;}"
?> |
The JSON encoder is recursive, and it's far from easy to make it iterative. Add a cheap stack limit check to prevent a segfault. This uses the PHP_JSON_ERROR_DEPTH error code that already talks about the stack depth. Previously this was only used for the $depth argument.
* PHP-8.3: Fix GH-15168: stack overflow in json_encode()
* PHP-8.4: Fix GH-15168: stack overflow in json_encode()
The JSON encoder is recursive, and it's far from easy to make it iterative. Add a cheap stack limit check to prevent a segfault. This uses the PHP_JSON_ERROR_DEPTH error code that already talks about the stack depth. Previously this was only used for the $depth argument. Closes phpGH-16059.
The JSON encoder is recursive, and it's far from easy to make it iterative. Add a cheap stack limit check to prevent a segfault. This uses the PHP_JSON_ERROR_DEPTH error code that already talks about the stack depth. Previously this was only used for the $depth argument. Closes phpGH-16059.
somehow Alpinelinux s390x builder been stuck after this change so filed #16528 |
Description
The following code:
Resulted in this output:
PHP Version
PHP 8.4.0-dev
Operating System
ubuntu 22.04
The text was updated successfully, but these errors were encountered: