php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43522 stream_get_line eats additional characters
Submitted: 2007-12-06 17:16 UTC Modified: 2007-12-10 14:40 UTC
From: tylera at iproduction dot com Assigned:
Status: Closed Package: Streams related
PHP Version: 5.2.5 OS: Gentoo Linux, Win32, Solaris
Private report: No CVE-ID: None
 [2007-12-06 17:16 UTC] tylera at iproduction dot com
Description:
------------
Calling stream_get_line may eat additional characters when reading a long line.  If the delimiter is not encountered, a number of additional characters are removed from the stream and are not returned with the next call to stream_get_line.  For some unknown reason, adding \r to the delimiter makes it work just fine.

Reproduce code:
---------------
<?PHP // 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ

$fp = fopen('test.php', 'r'); // Open myself
DoTest($fp, 'ZZZ');  // Removes 3 characters
DoTest($fp, "\r");  // Doesn't break with \r for some reason

function DoTest($fp, $delim) {
	echo "Delim:  " . urlencode($delim) . "\n";
	rewind($fp);
	echo "   " . stream_get_line($fp, 10, $delim) . "\n";
	echo "   " . stream_get_line($fp, 10, $delim) . "\n";
}

Expected result:
----------------
Delim:  ZZZ
   <?PHP // 1
   234567890A
Delim:  %0D
   <?PHP // 1
   234567890A


Actual result:
--------------
Delim:  ZZZ
   <?PHP // 1
   567890ABCD
Delim:  %0D
   <?PHP // 1
   234567890A


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-08 20:25 UTC] felipe@php.net
Simple patch for it:
http://ecl.zoone.com.br/etc/patches/bug43522.patch
 [2007-12-10 14:19 UTC] iliaa@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php


 [2007-12-10 14:40 UTC] tylera at iproduction dot com
Even though you used the wrong canned response, I appreciate that you fixed the bug.  Can't wait for 5.2.6 or 5.3.0 to be released.

http://cvs.php.net/viewvc.cgi/php-src/main/streams/streams.c?view=log
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 09:01:29 2024 UTC