From: franz at ess dot co dot at
Operating system: Red Hat 9.0
PHP version: 4.3.4
PHP Bug Type: Filesystem function related
Bug description: fread not binary safe
Description:
------------
I'm copying one binary file (currently GIF's) to another using fread on a
file or URL opened for binary reading.
The copy created is corrupted and doesn't has the same size as
the source.
The script runs nice under PHP-4.0.6 but fread seems to have
an error in version PHP-4.3.4.
Reproduce code:
---------------
<?php
// copies binary file "$from" to a file given by "$to"
function CopyBin($from,$to) {
if ($from) {
$input = fopen($from, "rb");
$image_data = "";
$totlen=0;
if($input) {
$i=0;
while(!feof($input))
{
$inp = fread($input, 10000);
$len = strlen($inp);
$totlen+= $len;
$i++;
$image_data = $image_data . $inp;
}
}
print ("Read in a Total of: $totlen\n");
fclose($input);
$output = fopen("$to", "wb");
fwrite($output, $image_data);
fclose($output);
}
}
CopyBin("source.gif","copy.gif");
?>
Expected result:
----------------
A copy of the binary file source.gif should be in copy.gif
Actual result:
--------------
If I diff -a the 2 files it looks like a few "\0" are missing.
--
Edit bug report at http://bugs.php.net/?id=27069&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=27069&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=27069&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=27069&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=27069&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=27069&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=27069&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=27069&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=27069&r=support
Expected behavior: http://bugs.php.net/fix.php?id=27069&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=27069&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=27069&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=27069&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27069&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=27069&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=27069&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=27069&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27069&r=float