Bug #11855 Updated: fgets returns truncated data
| From: | sniper@php.net | Date: | Sun, 19 Aug 2001 07:45:48 +0000 |
| Subject: | Bug #11855 Updated: fgets returns truncated data | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-63681@lists.php.net to get a copy of this message | ||
ID: 11855
Updated by: sniper
Reported By: wiersig@glamus.de
Old Status: Open
Status: Bogus
Bug Type: Filesystem function related
Operating System: Linux 2.2
PHP Version: 4.0.5
New Comment:
Yes, fread() is binary safe, fgets() isn't.
Not a bug.
--Jani
Previous Comments:
------------------------------------------------------------------------
[2001-07-03 10:12:27] wiersig@glamus.de
while reading chunks using fgets from a pdf-File, it occured that fgets seems to read data until a
0x0a occurs but returned the data until the first occurence of 0x00 only. Because of that, half of
the data was lost.
example
Hello0x0d0x0a
XYZ
will be read an returned correctly, the data containing "Hello" and the filepointer on the
XYZ
He0x00llo0x0d0x0a
XYZ
will retrurn data containing "He" with the filepointer still on the XYZ
my code:
$fp=fopen($pdf_file,"r");
while (!feof($fp)) {
$pdf_line="|".strtoupper(fgets($fp,4096));
$filepos+=strlen($pdf_line)-1;
$i=0;
while ($i=strpos($pdf_line,"Needle",$i)) {
if ($i<4000) {
$i+=strlen("Needle");
$retval[]=substr($pdf_line,$i,strlen("Needle"));
} else {
$i++;
}
}
if (strlen($pdf_line)>4000) {
fseek($fp,$filepos-100);
$filepos-=100;
}
}
fclose($fp);
we solved the problem by using fread() instead of fgets(), but felt you still might be interested.
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=11855&edit=1