php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18984 fread() add slashes on the content randomly
Submitted: 2002-08-20 08:58 UTC Modified: 2002-08-20 10:38 UTC
From: dams@php.net Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 4.1.2 OS: Linux debian 2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dams@php.net
New email:
PHP Version: OS:

 

 [2002-08-20 08:58 UTC] dams@php.net
Hi,

on my PHP 4.1.2, fread() adds randomly a addslashes() when 
reading a binary file. Here is the code : 
<?php
$fp=fopen($fichier,"r");
$attendu = filesize($fichier);

$attachmentorig=fread($fp,$attendu);

$lu = strlen($attachmentorig);

print "awaited : $attendu<BR>\n";
print "read : $lu<BR>\n";
fclose($fp);
?>

basically, it reads the file (I used any JPG picture as 
test), and then it happens sometimes (rather unusually) 
that the read size is about 10% bigger than the original 
file size.
The increase in size is always the same, when it happens. 

With further testing, I finally managed to find that, if 
the returned string is bigger than the original file size, 
then applying stripslashes() will solve the trouble.

I tested this also on 4.2.2 (macosx) and fresh 4.3.0-dev, 
and no trouble seems to be reproducable, so it may be a 
solved trouble. It may be a 4.1.2 specific trouble.

I hope this post will help anyone facing this trouble, or 
point some real bug.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-20 09:10 UTC] sander@php.net
Are you sure this isn't caused by one of the magic_quotes_* ini settings?
 [2002-08-20 09:13 UTC] nohn@php.net
Sorry, but the bug system is not the appropriate forum for asking
support questions. Your problem does not imply a bug in PHP itself.
For a list of more appropriate places to ask for help using PHP,
please visit http://www.php.net/support.php

Thank you for your interest in PHP.
 [2002-08-20 09:16 UTC] nohn@php.net
Verified on these systems as working:

awaited : 1170573
read : 1170573

Compaq Tru64 (php 4.3-dev, php 4.2-dev)
SuSE Linux (php 4.3-dev, php 4.2.2, php 4.0.6)

Magic quotes is off on every system:
 [2002-08-20 09:54 UTC] dams@php.net
sander : Magic quote is on. off or on, what is strange is 
that usually, there are no quotes added, and, suddenly, for 
a 10 to 20s laps, quotes are added.

Sebastian : 
your test confirm that this trouble seem to be away with 
PHP 4.2.x and upper. Yet, this is really happening 
unfrequently, and I may need up to 10 mins to have it 
happens.
 [2002-08-20 10:38 UTC] edink@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Sep 28 16:01:27 2024 UTC