php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30649 Invalid content with HTTP response > 8000 bytes
Submitted: 2004-11-01 13:57 UTC Modified: 2004-11-01 14:00 UTC
From: l dot zurschmiede at delightsoftware dot com Assigned:
Status: Not a bug Package: Sockets related
PHP Version: 5.0.2 OS: Linux 2.6.7
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: l dot zurschmiede at delightsoftware dot com
New email:
PHP Version: OS:

 

 [2004-11-01 13:57 UTC] l dot zurschmiede at delightsoftware dot com
Description:
------------
When a Socket/Stream function is used to get content,  
bigger then 8000bytes from a HTTP-Server, the received  
content has a false begin (3bb4 or similar) and end  
(0\n\n).  
  
This failure occures only if the Server does not respond  
with a "Content-Length: xx" header AND a clientside  
protocol of HTTP/1.1.  
If the clientside protocol is invalid (like "HTTP 1.1" or  
"HTTP 1.0") or it's an old one like HTTP/1.0, there is no  
failure. It only occures with HTTP/1.1 and NO serverside  
"Content-Length" header.  
  
The example-Script is a Server and a Client-Script. The  
Server-Script sends exactly 8001 bytes as content to the  
Client-Script. Comment out the "Content-Length" in Server,  
or the additional $cont .= "."; to retrieve the valid  
content.  
  
(Tested on PHP-5.0.2 with Apache 2.0.50, glibc-2.3.2) 
(A similarly one seams to be #28955) 

Reproduce code:
---------------
Client test_client.php:
<?php
$cont = '';
$head = '';
$fp = stream_socket_client('tcp://localhost:80', $errno, $error, 30);
fputs($fp, "POST /test_server.php HTTP/1.1\r\nHost: localhost\r\n");
fputs($fp, "Connection: Close\r\nAccept: text/xml\r\n\r\n");
while ( $str = trim(fgets($fp, 2048)) )
  $head .= $str;
while ( !(feof($fp)) )
  $cont .= fgets($fp, 2048);
fclose($fp);
print("Length: ".strlen($cont)."<br/>\r\nbegin (10): ".substr($cont, 0, 10)." <br/>\r\nend (10): ".substr($cont, (strlen($cont) - 10)));
?>

Server test_server.php:
<?php
$cont = '';
for ($i = 0; $i < 80; $i++)
  $cont .= '....................................................................................................';
$cont .= '.';
header('Content-Type: text/plain; charset=\"utf-8\"');
//header('Content-Length: '.strlen($cont));
print($cont);
?>

Expected result:
----------------
Length: 8001<br/> 
begin (10): .......... <br/> 
end (10): .......... 

Actual result:
--------------
Length: 8014<br/> 
begin (10): 1f41 
.... <br/> 
end (10): ... 
0 
 
******* 
There is no exception visible in a backtrace. 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-01 14:00 UTC] derick@php.net
This is not a bug, this is called "Chunked Encoding". See the HTTP RFCs for more information.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 15:01:34 2025 UTC