php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77663 incorrect counter of Json_decode depth
Submitted: 2019-02-24 16:44 UTC Modified: -
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: amir dot hossein7464 at gmail dot com Assigned:
Status: Open Package: json (PECL)
PHP Version: 7.1.26 OS: Gnu Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-02-24 16:44 UTC] amir dot hossein7464 at gmail dot com
Description:
------------
---
From manual page: https://php.net/function.json-decode
---
In the test script we have a array with depth:3 but when set depth to 3 in json_decode this drop a error and do not decode the json...
I think its a problem

Test script:
---------------
<?php
// Encode the data.
$json = json_encode(
    array(
        1 => array(
            'English' => array(
                'One',
                'January'
            ),
            'French' => array(
                'Une',
                'Janvier'
            )
        )
    )
);

// Define the errors.
$constants = get_defined_constants(true);
$json_errors = array();
foreach ($constants["json"] as $name => $value) {
    if (!strncmp($name, "JSON_ERROR_", 11)) {
        $json_errors[$value] = $name;
    }
}

// Show the errors for different depths.
foreach (range(1, 4) as $depth) {
    json_decode($json, true, $depth);
    echo "Last error: $depth ", $json_errors[json_last_error()], PHP_EOL;
}
?>



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-02-26 10:02 UTC] a at b dot c dot de
The top level also counts towards the "depth". Consider testing with $json=json_encode(42) and $json=json_encode(array()).
 [2019-03-07 00:10 UTC] amir dot hossein7464 at gmail dot com
I think its a problem because non array can not and should not pass as parameter for encode and just array should be allow.
If apply this logic the top level array should not be counted
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 14:01:25 2019 UTC