php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78397 Memory exhausted on custom recursion detection in phpunit
Submitted: 2019-08-10 18:01 UTC Modified: 2020-06-11 11:19 UTC
From: jeremy at derusse dot com Assigned: cmb (profile)
Status: Closed Package: Arrays related
PHP Version: 7.2.21 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
47 - 42 = ?
Subscribe to this entry?

 
 [2019-08-10 18:01 UTC] jeremy at derusse dot com
Description:
------------
We faced a segfault issue in Symfony test suite resumed to a simple empty PHPUnit script. https://github.com/sebastianbergmann/phpunit/issues/3790

after investigation, I found that PHPUnit detect circular reference in arrays by putting a marker in the array, and check in the recurcion if the data have the marker => if yes it's a circular reference. 

This issue: in PHP 7.2 the reference is lost somehow and the recurcion is not detected which cause either a segfault or a memory limit exeeded.

I tried to resume this issue to the simplest script possible (bellow).

output here: https://3v4l.org/6AASB

Few comments:

`array_slice` is totally useless in my code, but when I don't call it, everything work. Maybe it's the originator of the issue => see https://3v4l.org/MFjQI

the method `getData` which returns the recursive reference array is also useless, but, same as before, when I don't call it, everything work => https://3v4l.org/Q73bL




Test script:
---------------
<?php

function getData()
{
    $a[0] = &$a;

    return $a;
}

function recurcive(&$data)
{
    array_slice($data, 0);
    $data[] = 'X';
    if (end($data[0]) !== 'X') {
        recurcive($data[0]);
    }
}

$data = getData();
recurcive($data);


Expected result:
----------------
no ouput

Actual result:
--------------
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 20480 bytes) in /in/cDZmm on line 5

Process exited with code 255.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-08-16 11:10 UTC] sjon@php.net
-Summary: Issue with variable pass +Summary: Memory exhausted on custom recursion detection in phpunit -Status: Open +Status: Verified
 [2020-06-10 13:15 UTC] cmb@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: cmb
 [2020-06-10 13:15 UTC] cmb@php.net
This issue is fixed as of PHP 7.3.0[1]

[1] <http://git.php.net/?p=php-src.git;a=commit;h=777187cbafb8c1844971169dc97d38a633094aaf>
 [2020-06-11 08:00 UTC] jeremy at derusse dot com
-Status: Closed +Status: Assigned
 [2020-06-11 08:00 UTC] jeremy at derusse dot com
Thanks for taking care of this bug @cmb.

Is it possible to cherrypick the commit in 7.2 (maintained until Nov 30th?)
 [2020-06-11 11:19 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 [2020-06-11 11:19 UTC] cmb@php.net
PHP 7.2 only has security support until 2020-11-30[1], but this is
not a security issue.  So, no, the patch will not be back-ported.

[1] <https://www.php.net/supported-versions.php>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 01:01:28 2024 UTC