php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27069 fread not binary safe
Submitted: 2004-01-28 06:10 UTC Modified: 2004-01-28 09:25 UTC
From: franz at ess dot co dot at Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 4.3.4 OS: Red Hat 9.0
Private report: No CVE-ID: None
 [2004-01-28 06:10 UTC] franz at ess dot co dot at
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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-28 06:41 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

Works fine for me with the latest CVS.

 [2004-01-28 07:29 UTC] franz at ess dot co dot at
Ok, works with the snapshot below (4.3.5RC2 ?)
That was fast help, thanks.
 [2004-01-28 09:25 UTC] sniper@php.net
Fixed -> closed.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 02 15:01:31 2024 UTC