php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66608 Incorrect behavior with nested "finally" blocks
Submitted: 2014-01-30 03:24 UTC Modified: 2014-07-16 10:31 UTC
Votes:26
Avg. Score:2.3 ± 1.8
Reproduced:7 of 21 (33.3%)
Same Version:6 (85.7%)
Same OS:5 (71.4%)
From: drewparoski at gmail dot com Assigned: laruence (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.5.8 OS:
Private report: No CVE-ID: None
 [2014-01-30 03:24 UTC] drewparoski at gmail dot com
Description:
------------
The test script I provided _should_ print out "1", "2", "3", "4", and "5" in order and then it should exit gracefully.

When I run the test script under PHP 5.6.0alpha1 (downloaded and built today from http://downloads.php.net/tyrael/php-5.6.0alpha1.tar.gz), it prints out "1", "2", and "3", and then it gets stuck in an infinite loop that keeps printing out "4" over and over again. It never prints out "5" and the php process never exits.

I can consistently reproduce this behavior on my machine. I'm running CentOS Linux 6.3 on a 64-bit Intel Xeon processor, but I think this bug should be easily reproducible on most other platforms and processors.

I attached gdb to the php process to investigate, and it appears that the Zend engine is getting stuck in an infinite loop that keeps jumping between in execute_ex(), ZEND_JMP_SPEC_HANDLER(), ZEND_FAST_RET_SPEC_HANDLER(), and ZEND_ECHO_SPEC_CONST_HANDLER() from "zend_vm_execute.h".

I can also reproduce this bug with various builds of PHP 5.5.0.

Test script:
---------------
<?php
function bar() {
  try {
    echo "1\n";
  } finally {
    try {
      throw new Exception("");
    } catch (Exception $ab) {
      echo "2\n";
    } finally {
      echo "3\n";
    }
    echo "4\n";
  }
  echo "5\n";
}
bar();

Expected result:
----------------
1
2
3
4
5

Actual result:
--------------
1
2
3
4
4
4
4
4
4
4
4
... the php process keeps printing "4" over and over forever ...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-02-01 02:44 UTC] drewparoski at gmail dot com
-Package: *General Issues +Package: Scripting Engine problem
 [2014-02-01 02:44 UTC] drewparoski at gmail dot com
Changed the bug category from "General Issues" to "Scripting Engine problem".
 [2014-02-04 01:37 UTC] drewparoski at gmail dot com
-PHP Version: 5.6.0alpha1 +PHP Version: 5.5.8
 [2014-02-04 01:37 UTC] drewparoski at gmail dot com
Verified this happens on PHP 5.5.8, which is the current official release. Updated the version number for this bug accordingly, though it's worth noting this bug still happens on PHP 5.6.0alpha1 as well.
 [2014-07-15 18:20 UTC] nikic@php.net
-Status: Open +Status: Verified -Operating System: CentOS Linux 6.3 +Operating System: -Assigned To: +Assigned To: dmitry
 [2014-07-16 10:31 UTC] laruence@php.net
-Assigned To: dmitry +Assigned To: laruence
 [2014-07-18 07:51 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=de433d4c4756e18515e4b394298f9e3e60009692
Log: Fixed bug #66608 (Incorrect behavior with nested &quot;finally&quot; blocks)
 [2014-07-18 07:51 UTC] laruence@php.net
-Status: Verified +Status: Closed
 [2014-07-18 08:27 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=de433d4c4756e18515e4b394298f9e3e60009692
Log: Fixed bug #66608 (Incorrect behavior with nested &quot;finally&quot; blocks)
 [2014-07-21 09:30 UTC] ab@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=de433d4c4756e18515e4b394298f9e3e60009692
Log: Fixed bug #66608 (Incorrect behavior with nested &quot;finally&quot; blocks)
 [2014-07-21 10:02 UTC] ab@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=de433d4c4756e18515e4b394298f9e3e60009692
Log: Fixed bug #66608 (Incorrect behavior with nested &quot;finally&quot; blocks)
 [2014-07-30 09:52 UTC] tyrael@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=de433d4c4756e18515e4b394298f9e3e60009692
Log: Fixed bug #66608 (Incorrect behavior with nested &quot;finally&quot; blocks)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC