php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78539 Segfault with json_decode
Submitted: 2019-09-14 20:33 UTC Modified: 2019-09-18 22:42 UTC
From: ymaheo at hexaglobe dot com Assigned:
Status: Open Package: JSON related
PHP Version: 7.3.9 OS: CentOS Linux release 7.4.1708 (C
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-09-14 20:33 UTC] ymaheo at hexaglobe dot com
Description:
------------
PHP crash randomly on json_decode

We do not succeed to find a consistent way to reproduice the issue.

Test script:
---------------
N/A

Expected result:
----------------
No segfault

Actual result:
--------------
Fri Sep 13 21:08:16.078034 2019] [core:notice] [pid 65411] AH00051: child pid 169661 exit signal Segmentation fault (11), possible coredump in /home/apache_core
[Fri Sep 13 21:17:04.545743 2019] [core:notice] [pid 65411] AH00051: child pid 26553 exit signal Segmentation fault (11), possible coredump in /home/apache_core
[Fri Sep 13 21:17:09.549116 2019] [core:notice] [pid 65411] AH00051: child pid 136671 exit signal Segmentation fault (11), possible coredump in /home/apache_core
[Fri Sep 13 21:23:10.883202 2019] [core:notice] [pid 65411] AH00051: child pid 73382 exit signal Segmentation fault (11), possible coredump in /home/apache_core
[Fri Sep 13 21:23:16.890704 2019] [core:notice] [pid 65411] AH00051: child pid 61619 exit signal Segmentation fault (11), possible coredump in /home/apache_co


gdb) bt
#0 zend_mm_alloc_small (bin_num=6, size=56, heap=0x7f1717a00040) at /usr/src/debug/php-7.3.9/Zend/zend_alloc.c:1289
#1 _emalloc_56 () at /usr/src/debug/php-7.3.9/Zend/zend_alloc.c:2423
#2 0x00007f171fd92829 in _zend_new_array_0 () at /usr/src/debug/php-7.3.9/Zend/zend_hash.c:217
#3 0x00007f170f24bf09 in php_json_parser_array_create (parser=<optimized out>, array=0x7ffc96ba1660) at /usr/src/debug/php-7.3.9/ext/json/json_parser.tab.c:1859
#4 0x00007f170f24c6f9 in php_json_yyparse (parser=parser@entry=0x7ffc96ba2b20) at /usr/src/debug/php-7.3.9/ext/json/json_parser.tab.c:1593
#5 0x00007f170f249556 in php_json_decode_ex (return_value=return_value@entry=0x7f1717a1bed0, 
str=str@entry=0x7f16e2c8b018 "{\"i\":50404029,\"s\":\"dispo\",\"d\":false,\"TIMESTAMP\":1568389265,\"fa\":\"6912ed310195a0e91823d336ea3c61d1\",\"t\":0,\"t2\":0,"..., str_len=str_len@entry=1212, options=1, depth=<optimized out>) at /usr/src/debug/php-7.3.9/ext/json/json.c:252
#6 0x00007f170f249729 in zif_json_decode (execute_data=0x7f1717a1bf10, return_value=0x7f1717a1bed0) at /usr/src/debug/php-7.3.9/ext/json/json.c:361
#7 0x00007f171fe11628 in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER () at /usr/src/debug/php-7.3.9/Zend/zend_vm_execute.h:690
#8 execute_ex (ex=0x7f1717a00040) at /usr/src/debug/php-7.3.9/Zend/zend_vm_execute.h:55465
#9 0x00007f171fe15e83 in zend_execute (op_array=op_array@entry=0x7f1717a88000, return_value=0x0, return_value@entry=0x7f16eb5ee5e0) at /usr/src/debug/php-7.3.9/Zend/zend_vm_execute.h:60881
#10 0x00007f171fd868c2 in zend_execute_scripts (type=type@entry=8, retval=0x7f16eb5ee5e0, retval@entry=0x0, file_count=396475984, file_count@entry=3) at /usr/src/debug/php-7.3.9/Zend/zend.c:1568
#11 0x00007f171fd264f0 in php_execute_script (primary_file=primary_file@entry=0x7ffc96ba5140) at /usr/src/debug/php-7.3.9/main/main.c:2639
#12 0x00007f171fe180b2 in php_handler (r=<optimized out>) at /usr/src/debug/php-7.3.9/sapi/apache2handler/sapi_apache2.c:699
#13 0x0000560bdb7b0990 in ?? ()
#14 0x0000560bdd2cb418 in ?? ()
#15 0x0000560bdcf8e410 in ?? ()
#16 0x0000560bdd2c9df0 in ?? ()
#17 0x0000560bdb7b0ed9 in ?? ()
#18 0x0000560bdcf926c0 in ?? ()
#19 0x0000560bdb7a9b5f in ?? ()
#20 0x0000000000000000 in ?? ()

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-09-15 01:45 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2019-09-15 01:45 UTC] requinix@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

...or at least the JSON string that's crashing.
 [2019-09-16 19:59 UTC] ymaheo at hexaglobe dot com
-Status: Feedback +Status: Open
 [2019-09-16 19:59 UTC] ymaheo at hexaglobe dot com
After review, it seems that the segfault is not located in JSON part, but in zend_alloc.

We have some other backtraces where it happens in other parts of code. The issue is PHP memory allocation and all these segfaults happen in zend_mm_alloc_small.

#0 zend_mm_alloc_small (bin_num=6, size=56, heap=0x7f1717a00040) at /usr/src/debug/php-7.3.9/Zend/zend_alloc.c:1289
#1 zend_mm_alloc_heap (size=56, heap=0x7f1717a00040) at /usr/src/debug/php-7.3.9/Zend/zend_alloc.c:1360
#2 _emalloc (size=size@entry=56) at /usr/src/debug/php-7.3.9/Zend/zend_alloc.c:2500
#3 0x00007f171fd7ef46 in zend_string_alloc (persistent=0, len=26) at /usr/src/debug/php-7.3.9/Zend/zend_string.h:133
#4 concat_function (result=0x7f1717a1bea0, op1=<optimized out>, op1@entry=0x7f1717a1beb0, op2=0x7ffc96ba2bd0, op2@entry=0x7f1717a1bec0) at /usr/src/debug/php-7.3.9/Zend/zend_operators.c:1852
#5 0x00007f171fdd9365 in ZEND_CONCAT_SPEC_TMPVAR_TMPVAR_HANDLER () at /usr/src/debug/php-7.3.9/Zend/zend_vm_execute.h:14723
#6 0x00007f171fe0f1a4 in execute_ex (ex=0x2fce00) at /usr/src/debug/php-7.3.9/Zend/zend_vm_execute.h:57011
#7 0x00007f171fe15e83 in zend_execute (op_array=op_array@entry=0x7f1717a721c0, return_value=0x0, return_value@entry=0x7f16ec5130b8) at /usr/src/debug/php-7.3.9/Zend/zend_vm_execute.h:60881
#8 0x00007f171fd868c2 in zend_execute_scripts (type=type@entry=8, retval=0x7f16ec5130b8, retval@entry=0x0, file_count=396475968, file_count@entry=3) at /usr/src/debug/php-7.3.9/Zend/zend.c:1568
#9 0x00007f171fd264f0 in php_execute_script (primary_file=primary_file@entry=0x7ffc96ba5140) at /usr/src/debug/php-7.3.9/main/main.c:2639
#10 0x00007f171fe180b2 in php_handler (r=<optimized out>) at /usr/src/debug/php-7.3.9/sapi/apache2handler/sapi_apache2.c:699
#11 0x0000560bdb7b0990 in ?? ()
#12 0x0000560bdd16cd78 in ?? ()
#13 0x0000560bdcf87800 in ?? ()
#14 0x0000560bdd16b3f0 in ?? ()
#15 0x0000560bdb7b0ed9 in ?? ()
#16 0x0000560bdcf9e990 in ?? ()
#17 0x0000560bdb7a9b5f in ?? ()
#18 0x0000000000000000 in ?? ()
 [2019-09-18 20:23 UTC] henri dot hila at gmail dot com
Hi there,

Is there a fix / patch for this issue? We upgraded to php 7.3.9 over the weekend and we are now seeing this issue. 

Please let us know if a fix / patch is in place.

Thanks.
 [2019-09-18 20:29 UTC] nikic@php.net
-Status: Open +Status: Feedback
 [2019-09-18 20:29 UTC] nikic@php.net
There isn't much to go on here ... a lot of crashes manifest in zend_alloc, but have different root causes.

@henri dot hila at gmail dot com: To clarify, you are seeing this issue after upgrading from 7.3.8 to 7.3.9?
 [2019-09-18 20:50 UTC] henri dot hila at gmail dot com
@nikic@php.net 

I upgraded from 7.1.x to 7.3.9
 [2019-09-18 22:31 UTC] henri dot hila at gmail dot com
Hi,

Please update the status back to open as this is still an issue.

Thanks.
 [2019-09-18 22:42 UTC] requinix@php.net
-Status: Feedback +Status: Open
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Oct 22 16:01:28 2019 UTC