From:             vpavlov at rila dot bg
Operating system: Linux (SLES 9)
PHP version:      4.4.4
PHP Bug Type:     Filesystem function related
Bug description:  magic_quotes_runtime breaks *binary* fread()

Description:
------------
using fread() on a file opened with fopen(..., "rb") will mis-read the
file when magic_quotes_runtime is ON. According to documentation:

If magic_quotes_runtime is enabled, most functions that return data from
any sort of external source including databases and ->text files<- will
have quotes escaped with a backslash.



Reproduce code:
---------------
// TEST 1
set_magic_quotes_runtime(1);

$fp = fopen("bahor.zip", "rb");
$contents = fread($fp, filesize("bahor.zip"));
echo strlen($contents) . "\n";
echo filesize("bahor.zip") . "\n";
fclose($fp);

// TEST 2
set_magic_quotes_runtime(0);

$fp = fopen("bahor.zip", "rb");
$contents = fread($fp, filesize("bahor.zip"));
echo strlen($contents) . "\n";
echo filesize("bahor.zip") . "\n";
fclose($fp);


Expected result:
----------------
When I say binary I do mean binary, regardless of what some option claims.
In the code above, the two sections should produce the same results, the
exact size of the zip file.

Actual result:
--------------
In test 1 the sizes reported by filesize("bahor.zip") and
strlen($contents) are different, due to the escaping which occurs because
of magic_quotes_runtime being On

-- 
Edit bug report at http://bugs.php.net/?id=39536&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=39536&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=39536&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=39536&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=39536&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=39536&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=39536&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=39536&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=39536&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=39536&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=39536&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=39536&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=39536&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=39536&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=39536&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=39536&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=39536&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=39536&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=39536&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=39536&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=39536&r=mysqlcfg

Reply via email to