php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74431 foreach infinite loop
Submitted: 2017-04-13 10:02 UTC Modified: 2017-04-14 14:27 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: onceatease at gmail dot com Assigned:
Status: Closed Package: opcache
PHP Version: 7.1.2 OS: Ubuntu 12.04.5 LTS
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: onceatease at gmail dot com
New email:
PHP Version: OS:

 

 [2017-04-13 10:02 UTC] onceatease at gmail dot com
Description:
------------
foreach will infinite loop in php-fpm, in the case  while condition is literal and if conditon is a variable(in both php7.1.2 and php7.1.4)

Test script:
---------------
   $arr = [1,2];
   $j = 0;
   $cond = true;
   foreach ($arr as $i => $v){
        while(1){
            if($cond){
                break;
            }
        }
        $j++;
        echo $j."<br>";
       //if($j>100) break;
    }


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-13 10:07 UTC] onceatease at gmail dot com
-PHP Version: 7.1.3 +PHP Version: 7.1.2
 [2017-04-13 10:07 UTC] onceatease at gmail dot com
exec correctly in php7.1.0
test without php7.1.3
 [2017-04-13 20:30 UTC] ekin at coproductivity dot com
I cannot reproduce this with php-fpm on any of 7.1.2, 7.1.3 or 7.1.4 on Ubuntu 16.04 LTS, having opcache enabled. Which related opcache settings did you use?
 [2017-04-14 07:36 UTC] onceatease at gmail dot com
The code should be included in the function
function test(){
	$arr = [1,2];
    $j = 0;
    $cond = true;
    foreach ($arr as $i => $v){
        while(1){
            if($cond){
                break;
            }
        }
        $j++;
        echo $j."<br>";
       //if($j>100) break;
    }
}

test();
 [2017-04-14 14:27 UTC] pollita@php.net
Disabling the opcacge optimizer makes this go away, so it's probably in the break/cont optimization.
 [2017-04-14 15:01 UTC] ekin at coproductivity dot com
I was able to reproduce that it causes an infinite loop when in a function on versions above 7.1.0. Also it's not just php-fpm, can also see it behaves the same on cli. Opened a PR with failing test https://github.com/php/php-src/pull/2479
 [2017-04-14 20:04 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3ffe2cd251731d68493becf8ebbe6312ee86bb8d
Log: Fixed bug #74431
 [2017-04-14 20:04 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 15 09:01:26 2024 UTC