php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42090 json_decode causes segmentation fault
Submitted: 2007-07-24 20:42 UTC Modified: 2007-07-24 23:02 UTC
From: iknowatim at yahoo dot com Assigned: bjori (profile)
Status: Closed Package: Reproducible crash
PHP Version: 5.2.3 OS: Linux (Ubuntu)
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: iknowatim at yahoo dot com
New email:
PHP Version: OS:

 

 [2007-07-24 20:42 UTC] iknowatim at yahoo dot com
Description:
------------
JSON Version 1.2.1

The following program causes PHP to exit with a segmentation fault:

<?php

json_decode("\"");

?>

Instead, it should fail gracefully ("\"" is not valid JSON) and return NULL.

The <a href="http://www.json.org/JSON_checker/">JSON checker</a> correctly reports that it is invalid input: 
"syntax error at character 0"


Reproduce code:
---------------
<?php

print_r(json_decode("\""));

?>

Expected result:
----------------
NULL

Actual result:
--------------
Segmentation fault (core dumped)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-24 23:02 UTC] bjori@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

FYI: Your expected result is wrong, PHP allows you to "decode" non-valid JSON data:
json_decode("foo"); // string(3) "foo"
json_decode('"'); // string(1) """


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 10:01:29 2024 UTC