php cli crashes on uncaught derived exception

Bug #198246 reported by marmida on 2008-03-04
2
Affects Status Importance Assigned to Milestone
php5 (Ubuntu)
Undecided
Unassigned

Bug Description

Binary package hint: php5-cli

PHP on the cli dies with "zend_mm_heap corrupted" when handling a script that throws an exception extended from the base Exception class. If not caught, the crash happens. This only occurs for extensions of Exception; php executing uncaught base Exception instances exits cleanly.

Shell session:

marmida@marmida-desktop:/www/skyraise/wc/cli$ php -r "class TestException extends Exception {}; throw new TestException('hello');"

Fatal error: Uncaught exception 'TestException' with message 'hello' in Command line code:1
Stack trace:
#0 {main}
  thrown in Command line code on line 1
zend_mm_heap corrupted

Test PHP script:

class TestException extends Exception {}
throw new TestException('hello');

System: gutsy / 7.10

Expected results (from another machine):
[marmida@138210-web1 ~]$ php -r "class TestException extends Exception {}; throw new TestException('hello');"
PHP Fatal error: Uncaught exception 'TestException' with message 'hello' in Command line code:1
Stack trace:
#0 {main}
  thrown in Command line code on line 1
[marmida@138210-web1 ~]$

Chuck Short (zulcss) wrote :

Thanks or the bug report. I am able to kind of reproduce this in hardy. What is the output you expect?

Thanks
chuck

Changed in php5:
status: New → Triaged
marmida (michael-frood) wrote :

Sorry, it's hard to see the expected results in that blob of text above. It's this portion:

[marmida@138210-web1 ~]$ php -r "class TestException extends Exception {}; throw new TestException('hello');"
PHP Fatal error: Uncaught exception 'TestException' with message 'hello' in Command line code:1
Stack trace:
#0 {main}
  thrown in Command line code on line 1
[marmida@138210-web1 ~]$

The only real difference is the "zend_mm_heap corrupted." I've not checked to see if this kills PHP code that's supposed to execute on exit, like class destructors and shutdown functions. Would you like me to check those things out?

Chuck Short (zulcss) wrote :

Yes please.

Thanks
chuck

Two things:

- the bug does not effect scripts executed via 'php filename'; this only hits php -r with the contained code.
- the bug does stop shutdown handlers from being executed properly.

I've attached a file that should reproduce the error. If run as 'php test_cli_error.php', it should execute cleanly; if the contents of that file are copied out of the script (minus php tags) you should get the zend_mm_heap_corrupted exit without the output from the shutdown function.

Because this only impacts code evaluated via the -r option, it may not be worth investigating further.

Here is a sample shell session:

marmida@marmida-desktop:~$ php -r "class TestException extends Exception {}
function a() { print('shutdown' . chr(10)); }
register_shutdown_function('a');
throw new TestException('hello world');
"

Fatal error: Uncaught exception 'TestException' with message 'hello world' in Command line code:4
Stack trace:
#0 {main}
  thrown in Command line code on line 4
zend_mm_heap corrupted
marmida@marmida-desktop:~$ php test_cli_error.php

Fatal error: Uncaught exception 'TestException' with message 'hello world' in /home/marmida/test_cli_error.php:6
Stack trace:
#0 {main}
  thrown in /home/marmida/test_cli_error.php on line 6
shutdown
marmida@marmida-desktop:~$

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers