From: geoffrey at google dot com Operating system: Redhat Linux 2.4.22 PHP version: 5.1.6 PHP Bug Type: Filesystem function related Bug description: fseek returns false if offset is over 10GB (10737418239 bytes)
Description: ------------ fseek returns false if offset is over 10GB (10737418239 bytes). This could be an underlying problem with llseek. I'm running php 5.1.6. my config line: CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" ./configure Using stock php.ini-dist Reproduce code: --------------- #!/usr/local/src/php-5.1.6/sapi/cli/php -q <? $file = "bigfile"; // file is 20GB large $fp = fopen($file, 'r'); fseek($fp, 10737418239, SEEK_CUR); $line = fgets($fp, 512); echo $line; // prints the correct line echo ftell($fp); // returns -214748361201 rewind($fp); fseek($fp, 10737418240, SEEK_CUR); $line = fgets($fp, 512); echo $line; // prints the first line of the file echo ftell($fp); // returns 54 which is the strlen() of line 1 Expected result: ---------------- both fseeks should be 1 byte apart and should return successful. Both fgets should return the same data only 1 byte apart. ftell should return 10737418239 for the first run and 10737418240 for the second. Actual result: -------------- The first fseek is successful and fgets returns the correct bytes. The second fseek (1 byte beyond 10GB) fails and returns bytes at the begining of the file. ftell also seems broken as it returns -214748361201 in the first run. It returns the correct offset in the second because fseek fails and sets the offset to the begining of the file. strace output: <snip>... lstat64("bigfile", {st_mode=S_IFREG|0666, st_size=20304186228, ...}) = 0 open("bigfile", O_RDONLY|O_LARGEFILE) = 3 fstat64(3, {st_mode=S_IFREG|0666, st_size=20304186228, ...}) = 0 _llseek(3, 0, [0], SEEK_CUR) = 0 _llseek(3, 2147483647, [2147483647], SEEK_SET) = 0 read(3, "<snip>"..., 8192) = 8192 write(1, "<snip>"..., 37,<snip> ) = 37 write(1, "-2147483612", 11-2147483612) = 11 _llseek(3, 0, [0], SEEK_SET) = 0 _llseek(3, 18446744071562067968, 0xbfffcdf0, SEEK_SET) = -1 EINVAL (Invalid argument) read(3, "<snip>"..., 8192) = 8192 write(1, "<snip>"..., 54<snip> ) = 54 write(1, "54", 254) = 2 close(3) = 0 close(0) ...</snip> Geoff -- Edit bug report at http://bugs.php.net/?id=38758&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=38758&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=38758&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=38758&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=38758&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=38758&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=38758&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=38758&r=needscript Try newer version: http://bugs.php.net/fix.php?id=38758&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=38758&r=support Expected behavior: http://bugs.php.net/fix.php?id=38758&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=38758&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=38758&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=38758&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38758&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=38758&r=dst IIS Stability: http://bugs.php.net/fix.php?id=38758&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=38758&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=38758&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=38758&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=38758&r=mysqlcfg