Bug #80026 [NEW]: custom ob_start with ob_gzhandler resending headers and generating corrupted ou
From: marcelotpcruz at gmail dot com
Operating system: Windows 10
PHP version: 7.4.9
Package: HTTP related
Bug Type: Bug
Bug description:custom ob_start with ob_gzhandler resending headers and generating corrupted ou
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/
--
Edit bug report at https://bugs.php.net/bug.php?id=80026&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80026&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80026&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80026&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80026&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80026&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80026&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80026&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80026&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80026&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80026&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80026&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80026&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80026&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80026&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80026&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80026&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80026&r=mysqlcfg
Thread (2 messages)
- marcelotpcruz at gmail dot com