php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80026 custom ob_start with ob_gzhandler resending headers and generating corrupted ou
Submitted: 2020-08-27 15:08 UTC Modified: 2020-08-28 07:36 UTC
From: marcelotpcruz at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: HTTP related
PHP Version: 7.4.9 OS: Windows 10
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: marcelotpcruz at gmail dot com
New email:
PHP Version: OS:

 

 [2020-08-27 15:08 UTC] marcelotpcruz at gmail dot com
Description:
------------
When using ob_start with a custom calback ob_gzhandler tries resending headers and also generate a corrupted output.

Both generates same headers with exception of:
//Response Headers
Keep-Alive: timeout=5, max=100 // Script with fine Output
Keep-Alive: timeout=5, max=99 // Script with bad output

//Request Headers
Sec-Fetch-Site: none        // Script with fine Output
Sec-Fetch-Site: same-origin // Script with bad Output

Test script:
---------------
// Script with fine Output
<?php
header( 'Content-type: text/html; charset=utf-8' );
ob_start("ob_gzhandler");
echo 'Begin ...<br />';
for( $i = 0 ; $i < 5 ; $i++ )
{
    echo $i . '<br />';
    ob_end_flush();
    flush();
    ob_flush();
    ob_start("ob_gzhandler");
    sleep(1);
}
echo 'End ...<br />';





// Script with bad Output
<?php
function ob_chunked_gzhandler($buffer, $phase)
{ //compression on
    $buffer                = ob_gzhandler($buffer, $phase);//<--fourth line
    $length                 = strlen($buffer);
    return dechex($length) . "\r\n$buffer\r\n";
}

header('Content-type: text/html; charset=utf-8');
ob_start("ob_chunked_gzhandler");
echo 'Begin ...<br />';
for ($i = 0; $i < 10; $i++) {
    echo $i . '<br />';
    ob_end_flush();
    flush();
    ob_flush();
    ob_start("ob_chunked_gzhandler");
    sleep(1);
}
echo 'End ...<br />';


Expected result:
----------------
//Outputs fine:
Begin ...
0
1
2
3
4
End ...

Actual result:
--------------
55RW sJM��S��ӳI*Rз3�P���2 1b � 3�I*RзR�4) 1b � 3�I*Rзσ� 1b � 3�I*Rз{��� 1b � 3�I*Rз��{ 1b � 3�I*RзA�{� 1b � 3�I*Rзܧ�� 1b � 3�I*Rзh��J 1b � ��I*Rз�ܬ� 1b � ��I*Rз5�� 21 � s�KQ��ӳI*Rз��B


//Error.log file
[Thu Aug 27 11:53:48.261150 2020] [fcgid:warn] [pid 17632:tid 1148] [client ::1:6687] mod_fcgid: stderr: PHP Warning:  Cannot modify header information - headers already sent by (output started at C:\\server\\lec\\var\\www\\output_custom.php:16) in C:\\server\\lec\\var\\www\\output_custom.php on line 4, referer: http://localhost/


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-08-28 07:36 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-08-28 07:36 UTC] cmb@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Both scripts are erroneous; see
<https://www.php.net/ob_gzhandler>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 22:01:30 2024 UTC