php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39536 magic_quotes_runtime breaks *binary* fread()
Submitted: 2006-11-16 16:30 UTC Modified: 2006-11-17 07:59 UTC
From: vpavlov at rila dot bg Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.4.4 OS: Linux (SLES 9)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: vpavlov at rila dot bg
New email:
PHP Version: OS:

 

 [2006-11-16 16:30 UTC] vpavlov at rila dot bg
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-16 16:56 UTC] tony2001@php.net
That's right, this is how magic_quotes_runtime are supposed to work.
And there is nothing wrong with the docs. Yes, "*from
any sort of external source* *including* databases and text files". "Including" doesn't mean "only".
 [2006-11-17 07:59 UTC] vpavlov at rila dot bg
Well, if that's your notion of well written documentation... At the very least it's misleading. Changing the text to read "...including text and binary files..." will sure save a lot of hassle to people with the same problem.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 03 08:01:31 2024 UTC