From: alexander dot v at zend dot com
Operating system: Linux
PHP version: 6CVS-2005-10-05 (CVS)
PHP Bug Type: Filesystem function related
Bug description: fread doesn't move internal "position" pointer. fseek fails
as a result
Description:
------------
fread() doesn't move internal file pointer "stream->position" (could be
retrived by ftell()).
fseek(...,...,SEEK_CUR) fails if crosses buffer boundary as a result.
Reproduce code:
---------------
// 'testdata.dat' is a binary file.
// Each byte contains value equal to offset % 256
$f = fopen('testdata.dat', 'r');
printf( "offset (before read): 0x%X\n", ftell($f) );
$bin_str = fread($f, 16);
for ($count = 0; $count < 16; $count++) {
printf( "0x%02X ", ord($bin_str{$count}) );
}
printf( "\noffset (after read): 0x%X\n.....\n", ftell($f) );
fseek( $f, 16*1024, SEEK_CUR);
printf( "offset (before read): 0x%X\n", ftell($f) );
$bin_str = fread($f, 16);
for ($count = 0; $count < 16; $count++) {
printf( "0x%02X ", ord($bin_str{$count}) );
}
printf( "\noffset (after read): 0x%X\n", ftell($f) );
fclose( $f );
Expected result:
----------------
offset (before read): 0x0
0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E
0x0F
offset (after read): 0x10
.....
offset (before read): 0x4010
0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1A 0x1B 0x1C 0x1D 0x1E
0x1F
offset (after read): 0x4020
Actual result:
--------------
offset (before read): 0x0
0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E
0x0F
offset (after read): 0x0
.....
offset (before read): 0x4000
0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E
0x0F
offset (after read): 0x4000
--
Edit bug report at http://bugs.php.net/?id=34743&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=34743&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=34743&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=34743&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=34743&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=34743&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=34743&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=34743&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=34743&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=34743&r=support
Expected behavior: http://bugs.php.net/fix.php?id=34743&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=34743&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=34743&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=34743&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=34743&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=34743&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=34743&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=34743&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=34743&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=34743&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=34743&r=mysqlcfg