php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21131 fopen with "a+" and the a rewind does'nt work anymore
Submitted: 2002-12-21 08:25 UTC Modified: 2003-02-21 20:44 UTC
From: hgj at xs4all dot nl Assigned: wez (profile)
Status: Closed Package: Filesystem function related
PHP Version: 4.3.0RC4 OS: Linux 2.4.18 (Redhat)
Private report: No CVE-ID: None
 [2002-12-21 08:25 UTC] hgj at xs4all dot nl
With 4.2.3 and below the next code did give the contents of $file only when the Apache runtime user was allowed to update that file. Now it nevers gives the content of the file anymore.

$fp = fopen($file,"a+"); 
rewind($fp);
$fstr = fread($fp, filesize($file));

The PHP version box did not give 4.3.0RC4, but it's still there.

./configure --with-openssl --enable-cli --prefix=/www --with-mcrypt --with-config-file-path=/www/conf --with-mysql --with-apache=../apache_1.3.27 --enable-track-vars --with-gzlib


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-22 12:16 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 [2003-02-02 14:35 UTC] k.schroeder@php.net
ext/standard/tests/file/bug21131.phpt failed on W2k server with latetest win32-snap:

---- EXPECTED OUTPUT
int(6)
int(0)
foobar
---- ACTUAL OUTPUT
int(0)
int(0)
foobar
---- FAILED
 [2003-02-02 15:30 UTC] michael dot mauch at gmx dot de
Also on other systems (Solaris, some Linux versions). I think that test case is a bit wrong. There's no guarantee in the C standard that ftell() will point to the end of the file directly after fopen(...,"a+"). You are guaranteed that you can read from anywhere in the file, and that you can't overwrite anything in the file - writes go always to the end of the file, no matter how hard you fseek() or fsetpos().

Please see also:
<http://groups.google.de/groups?q=fopen+a%2B+ftell+Debian&hl=de&lr=&ie=UTF-8&scoring=d&selm=20030108144007%242401%40gated-at.bofh.it&rnum=1>
<http://groups.google.de/groups?q=fopen+a%2B+debian+closed&hl=de&lr=&ie=UTF-8&scoring=d&selm=handler.107966.D107966.101008948313895.ackdone%40bugs.debian.org&rnum=1>
 [2003-02-16 09:41 UTC] wez@php.net
Confirmed that the test is indeed bogus.
Looking in more depth at the streams functionality.
 [2003-02-21 20:44 UTC] wez@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC