php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24951 ob_flash() and ob_clean() destroy output handler
Submitted: 2003-08-05 08:31 UTC Modified: 2003-08-11 00:52 UTC
From: d dot stogov at turck dot spb dot ru Assigned: iliaa
Status: Closed Package: Output Control
PHP Version: 4.3.3RC2 OS: Linux
Private report: No CVE-ID:
 [2003-08-05 08:31 UTC] d dot stogov at turck dot spb dot ru
Description:
------------
The C function "php_end_ob_buffer" from "main/output.c" destroys output_handler on first call so the second call to output_handler is not possible. "php_end_ob_buffer" is called by "ob_flush()" and "ob_clean()" those must not destroy output handler.

Look into line 250:

zval_ptr_dtor(&OG(active_ob_buffer).output_handler);

The same error is in PHP-4.3.3RC2 too.

Reproduce code:
---------------
<?php

function test($s,$mode) {
  return (($mode & PHP_OUTPUT_HANDLER_START)?"[":"").
         $s.
         (($mode & PHP_OUTPUT_HANDLER_END)?"]\n":"");
}

function t1() {
  ob_start("test");
  echo "Hello from t1 1 ";
  echo "Hello from t1 2 ";
  ob_end_flush();
}

function t2() {
  ob_start("test");
  echo "Hello from t2 1 ";
  ob_flush();
  echo "Hello from t2 2 ";
  ob_end_flush();
}


function t3() {
  ob_start("test");
  echo "Hello from t3 1 ";
  ob_clean();
  echo "Hello from t3 2 ";
  ob_end_flush();
}

t1(); echo "\n";
t2(); echo "\n"; 
t3(); echo "\n";
?>

Expected result:
----------------
[Hello from t1 1 Hello from t1 2 ]

[Hello from t2 1 Hello from t2 2]

[Hello from t3 2]

Actual result:
--------------
[Hello from t1 1 Hello from t1 2 ]

[Hello from t2 1 Hello from t2 2
Hello from t3 2

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-08-05 11:05 UTC] sniper@php.net
Take that back, with latest CVS I get this output:

[Hello from t1 1 Hello from t1 2 ]

[Hello from t2 1 Hello from t2 2 ]

Hello from t3 2 ]

AFAIK, this is the expected output too..the 
 [2003-08-08 01:09 UTC] d dot stogov at turck dot spb dot ru
Seems to work with 4.3.3RC3 on Windows, but I think it is not fixed.
See into code of "php_end_ob_buffer". You destroy "output_handler" on each flush. (main/output.c:250)
The second call to "php_end_ob_buffer" will work only if memory which was used for "output_handler" was not changed.

May be I am not right, but check it.
 [2003-08-08 11:49 UTC] iliaa@php.net
The following patch appears to address the problem, please try it and let me know if it works for you as well.
http://bb.prohost.org/bug24951.txt
 [2003-08-08 18:44 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 [2003-08-11 00:52 UTC] d dot stogov at turck dot spb dot ru
I have tested path with PHP-4.3.2. 
All works fine.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sat Apr 19 06:02:27 2014 UTC