ID: 34743
User updated by: alexander dot v at zend dot com
Reported By: alexander dot v at zend dot com
Status: Open
Bug Type: Filesystem function related
Operating System: Linux
PHP Version: 6CVS-2005-10-05 (CVS)
New Comment:
Patch:
----------------------------------------------
Index: main/streams/streams.c
===================================================================
RCS file: /repository/php-src/main/streams/streams.c,v
retrieving revision 1.87
diff -u -r1.87 streams.c
--- main/streams/streams.c 22 Aug 2005 14:48:25 -0000 1.87
+++ main/streams/streams.c 5 Oct 2005 16:06:53 -0000
@@ -855,6 +855,8 @@
*pnum_chars = num_chars;
*pis_unicode = is_unicode;
+ stream->position += num_bytes;
+
if (num_chars == 0 && grow_mode) {
efree(buf);
buf = NULL;
Previous Comments:
------------------------------------------------------------------------
[2005-10-05 18:21:28] alexander dot v at zend dot com
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 this bug report at http://bugs.php.net/?id=34743&edit=1