From:             mpb dot mail at gmail dot com
Operating system: FreeBSD
PHP version:      5.0.4
PHP Bug Type:     Filesystem function related
Bug description:  stat() returns wrong size on large files (>2^31 bytes)

Description:
------------
stat() returns the wrong size for large files.  This is because a 64 bit
integer (at the OS level) is truncated to 32 bits (at the PHP level). 
(This will not be a problem on platforms where PHP integer type is 64
bits.)

In C, the stat() function returns st_size as type off_t, which I suspect
is 64 bits on most modern operatings systems.

I'm not sure what the solution for this is.  Perhaps if the size is
greater than PHP's maximum interegr value (varies by platform), then the
size is converted to a float?  This would be nice.

Looks like the filesize() function has a similar problem.

Perhaps you will consider this to be a "bogus" bug, but I really think PHP
can do better than arbitrarily converting 64 bit ints to 32 bit ints (which
can result in files with negative lengths).  If returning a float is not an
option, how about returning a size of -1, or MAX_INT, or an error code.

Reproduce code:
---------------
// verylargefile is 3751661568 bytes, in this case
$stat = lstat ('/path/to/verylargefile');
$size = $stat['size'];
print "size: $size\n";

Expected result:
----------------
size: 3751661568

Actual result:
--------------
size: -543305728

-- 
Edit bug report at http://bugs.php.net/?id=33738&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=33738&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=33738&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=33738&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=33738&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=33738&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=33738&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=33738&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=33738&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=33738&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=33738&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=33738&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=33738&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=33738&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=33738&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=33738&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=33738&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=33738&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=33738&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=33738&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=33738&r=mysqlcfg

Reply via email to