php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61541 Segfault using ob_clean/flush* functions in output_callback function
Submitted: 2012-03-28 11:48 UTC Modified: 2012-03-29 00:01 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: grzegorz129 at gmail dot com Assigned: yohgaki (profile)
Status: Closed Package: Reproducible crash
PHP Version: 5.3 OS: ANY
Private report: No CVE-ID: None
 [2012-03-28 11:48 UTC] grzegorz129 at gmail dot com
Description:
------------
I've trying to catch E_PARSE but trying to run sample code results only in 
segfault.

Test script:
---------------
<?php
 ob_start('phpErrorHandler');
 
 function phpErrorHandler($output) {
  ob_end_clean();
  echo "abc";
  die("def");
 }
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-28 14:51 UTC] sixd@php.net
-Summary: Memory leak during using ob_* +Summary: Segfault using ob_*
 [2012-03-28 14:51 UTC] sixd@php.net
Changed summary from "Memory leak during using ob_*"
 [2012-03-28 15:09 UTC] grzegorz129 at gmail dot com
Test script can be even simplier:

<?php
 ob_start('foo');
 function foo() { ob_end_clean(); }
?>
 [2012-03-28 16:40 UTC] reeze dot xia at gmail dot com
I've sent a pull request to fix this. @see https://github.com/php/php-src/pull/25
this makes php raise fatal error instead of segfault.

This seems to be a logic error when clean/flush output will cause the callback 
called and then endless function call.
 [2012-03-28 16:42 UTC] reeze dot xia at gmail dot com
@grzegorz129 maybe the title can be more specific: eg: Segfault using 
ob_clean/flush* functions in output_callback function
 [2012-03-28 17:49 UTC] grzegorz129 at gmail dot com
-Summary: Segfault using ob_* +Summary: Segfault using ob_clean/flush* functions in output_callback function
 [2012-03-28 17:49 UTC] grzegorz129 at gmail dot com
@reeze - thanks for patch & title suggestion.
Is there any way to catch E_PARSE? As you can see ob_* is dead end ;)
 [2012-03-28 18:28 UTC] yohgaki@php.net
-Status: Open +Status: Assigned -PHP Version: 5.3.10 +PHP Version: 5.3/5.4/5.5-dev
 [2012-03-28 18:28 UTC] yohgaki@php.net
This should work. Assign to myself.
 [2012-03-28 18:43 UTC] mike@php.net
Why has the PHP version of the report been changed?

This code works fine in PHP-5.4+
 [2012-03-28 18:58 UTC] yohgaki@php.net
-Operating System: Linux/debian lenny +Operating System: ANY
 [2012-03-28 18:58 UTC] yohgaki@php.net
--------
[yohgaki@dev php-src]$ cat t.php 
<?php
 ob_start('foo');
  function foo() { ob_end_clean(); }
  ?>
-------

This kind of code worked since the output buffer was introduced. i.e. Works from 
PHP 4.0.

It seems PHP5.4+ has newer API, but it just raise fatal error.
I was surprised now it's not working, so I'll fix this.

-------
[yohgaki@dev php-src]$ php -v
PHP 5.4.1RC1-dev (cli) (built: Mar 22 2012 17:06:46) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
[yohgaki@dev php-src]$ php t.php

Fatal error: ob_end_clean(): Cannot use output buffering in output buffering 
display handlers in /home/yohgaki/ext/git/oss/php.net/php-src/t.php on line 3
-------
 [2012-03-28 19:01 UTC] mike@php.net
Sure, it raises a fatal error, because I don't like crashes.
 [2012-03-28 19:04 UTC] grzegorz129 at gmail dot com
@mike - nooone like crashes but it should work instead of throwing E_FATAL. This 
kind of (tricky) code as I know is only way to catch errors which 
set_error_handler() just can't catch. If you know another way to do this propose, 
please.
 [2012-03-28 19:21 UTC] yohgaki@php.net
-PHP Version: 5.3/5.4/5.5-dev +PHP Version: 5.3
 [2012-03-28 19:21 UTC] yohgaki@php.net
I thought it worked for old PHPs, but it's not. So it would be OK to raise fatal 
error. Restored version.

I'll just add recursive call error to 5.3.
 [2012-03-28 23:55 UTC] reeze.xia@gmail.com@php.net
Automatic comment on behalf of reeze.xia@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=abd2b2ee4332e598f46efec0cac0a9f546bc4f2d
Log: - fix bug #61541, Segfault when using ob_* in output_callback
 [2012-03-28 23:55 UTC] reeze.xia@gmail.com@php.net
Automatic comment on behalf of reeze.xia@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9bc91a21db733b5e12ab6a4356b2470b72d784d5
Log: - fix bug #61541, Segfault when using ob_* in output_callback
 [2012-03-29 00:01 UTC] yohgaki@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: yohgaki
 [2012-03-29 00:01 UTC] yohgaki@php.net
patch is merged. 
Thank you.
 [2012-03-29 07:48 UTC] reeze.xia@gmail.com@php.net
Automatic comment on behalf of reeze.xia@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=abd2b2ee4332e598f46efec0cac0a9f546bc4f2d
Log: - fix bug #61541, Segfault when using ob_* in output_callback
 [2012-03-29 07:48 UTC] reeze.xia@gmail.com@php.net
Automatic comment on behalf of reeze.xia@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9bc91a21db733b5e12ab6a4356b2470b72d784d5
Log: - fix bug #61541, Segfault when using ob_* in output_callback
 [2014-10-07 23:27 UTC] stas@php.net
Automatic comment on behalf of reeze.xia@gmail.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=abd2b2ee4332e598f46efec0cac0a9f546bc4f2d
Log: - fix bug #61541, Segfault when using ob_* in output_callback
 [2014-10-07 23:28 UTC] stas@php.net
Automatic comment on behalf of reeze.xia@gmail.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=9bc91a21db733b5e12ab6a4356b2470b72d784d5
Log: - fix bug #61541, Segfault when using ob_* in output_callback
 [2014-10-07 23:38 UTC] stas@php.net
Automatic comment on behalf of reeze.xia@gmail.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=abd2b2ee4332e598f46efec0cac0a9f546bc4f2d
Log: - fix bug #61541, Segfault when using ob_* in output_callback
 [2014-10-07 23:38 UTC] stas@php.net
Automatic comment on behalf of reeze.xia@gmail.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=9bc91a21db733b5e12ab6a4356b2470b72d784d5
Log: - fix bug #61541, Segfault when using ob_* in output_callback
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 01:01:28 2024 UTC