Bug #76107 [Opn]: SplFileInfo returns incorrect information on large file in 32bit architecture
| From: | cmb@php.net | Date: | Wed, 15 Apr 2020 17:00:04 +0000 |
| Subject: | Bug #76107 [Opn]: SplFileInfo returns incorrect information on large file in 32bit architecture | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-226595@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76107&edit=1
ID: 76107
Updated by: cmb@php.net
Reported by: VeryCrazyDog at gmail dot com
Summary: SplFileInfo returns incorrect information on large
file in 32bit architecture
Status: Open
Type: Bug
Package: SPL related
Operating System: Arch Linux ARMv7
PHP Version: 7.2.3
Block user comment: N
Private report: N
New Comment:
Presumably, stat() fails with EOVERFLOW here, what could at least
trigger a more descriptive error message.
Interestingly, the given script mostly works on Windows x86,
albeit the reported size is wrong due to overflow[1].
[1] <https://github.com/php/php-src/blob/php-7.3.17/Zend/zend_virtual_cwd.c#L352-L355>
Previous Comments:
------------------------------------------------------------------------
[2018-03-17 06:45:44] VeryCrazyDog at gmail dot com
Description:
------------
When calling SplFileInfo::isFile() on a large file, false is returned instead of true.
When calling SplFileInfo::getMTime() and SplFileInfo::getSize() on a large file, RuntimeException is
throw.
This problem does not happens on Windows 7 64bit running same PHP version. It seems that it is
related the maximum value of int, because the file size which I used in the test is
"2939977728" which cannot be fit in 32bit OS.
Although it may not be possible to report the file size, it is expected at least, isFile() and
getMTime() should return the correct result.
Test script:
---------------
<?php
$info = new SplFileInfo('/path/to/large_file');
var_dump($info);
var_dump($info->isFile()); // This returns false
var_dump($info->isReadable());
var_dump($info->getMTime()); // This throws RuntimeException
var_dump($info->getSize()); // This throws RuntimeException
if ($info->isFile()) {
echo $info->getRealPath();
}
Expected result:
----------------
vcd@server ~$ php -f test.php
object(SplFileInfo)#1 (2) {
["pathName":"SplFileInfo":private]=>
string(24) "/home/vcd/tmp/large_file"
["fileName":"SplFileInfo":private]=>
string(10) "large_file"
}
bool(true)
bool(true)
int(1515414305)
bool(false)
/home/vcd/tmp/large_file
Actual result:
--------------
vcd@server ~$ php -f test.php
object(SplFileInfo)#1 (2) {
["pathName":"SplFileInfo":private]=>
string(24) "/home/vcd/tmp/large_file"
["fileName":"SplFileInfo":private]=>
string(10) "large_file"
}
bool(false)
bool(true)
PHP Fatal error: Uncaught RuntimeException: SplFileInfo::getMTime(): stat failed for
/home/vcd/tmp/large_file in /home/vcd/test.php:6
Stack trace:
#0 /home/vcd/test.php(6): SplFileInfo->getMTime()
#1 {main}
thrown in /home/vcd/test.php on line 6
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76107&edit=1