php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73792 invalid foreach loop hangs script
Submitted: 2016-12-20 11:54 UTC Modified: 2016-12-20 12:06 UTC
From: ryan dot brothers at gmail dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0 OS: Linux
Private report: No CVE-ID: None
 [2016-12-20 11:54 UTC] ryan dot brothers at gmail dot com
Description:
------------
When running the below in PHP 7.1.0, the foreach loop hangs the script, and my CPU goes to 100% utilization.

If &$value is changed to $value, then it runs cleanly.


Test script:
---------------
<?php
$a = 'aaa';

foreach ($a['bbb'] as &$value)
{
	echo 'loop';
}

unset($value);

echo 'done';


Expected result:
----------------
Warning: Illegal string offset 'bbb' in /tmp/test.php on line 4

Warning: Invalid argument supplied for foreach() in /tmp/test.php on line 4
done


Actual result:
--------------
Warning: Illegal string offset 'bbb' in /tmp/test.php on line 4

then it hangs


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-20 12:06 UTC] requinix@php.net
-Status: Open +Status: Verified -PHP Version: 7.1.0 +PHP Version: 7.0
 [2016-12-20 12:06 UTC] requinix@php.net
3v4l doesn't like it since 7.0. https://3v4l.org/YhlXN

On Windows, PHP 7.0.9 crashes (not responding) but 7.1.0 gives

Warning: Illegal string offset 'bbb' in - on line 4

Fatal error: Uncaught Error: Cannot return string offsets by reference in -:4
Stack trace:
#0 {main}
  thrown in - on line 4
 [2016-12-20 13:54 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3c6a2fb08cb8c0dddc16a62a816249c68132773d
Log: Fixed bug #73792 (invalid foreach loop hangs script)
 [2016-12-20 13:54 UTC] dmitry@php.net
-Status: Verified +Status: Closed
 [2016-12-20 13:55 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3c6a2fb08cb8c0dddc16a62a816249c68132773d
Log: Fixed bug #73792 (invalid foreach loop hangs script)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 09:01:30 2024 UTC