Bug #80654 [Opn]: file_get_contents() maxlen fails above (2**31)-1 bytes
| From: | cmb@php.net | Date: | Thu, 28 Jan 2021 16:09:17 +0000 |
| Subject: | Bug #80654 [Opn]: file_get_contents() maxlen fails above (2**31)-1 bytes | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-231821@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80654&edit=1
ID: 80654
Updated by: cmb@php.net
Reported by: divinity76+spam at gmail dot com
Summary: file_get_contents() maxlen fails above (2**31)-1
bytes
Status: Open
Type: Bug
Package: *Directory/Filesystem functions
PHP Version: 7.3.26
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
The same happens with stream_get_contents().
Previous Comments:
------------------------------------------------------------------------
[2021-01-22 02:35:54] divinity76+spam at gmail dot com
Description:
------------
when file_get_contents() is instructed to get the first (2**31) bytes of a file that is exactly
(2**31) bytes big, php will only fetch the first (2**31)-1 bytes.
Test script:
---------------
rm -f bug;
dd if=/dev/null count=0 bs=1 seek=2147483648 of=bug;
php -r
'ini_set("memory_limit","-1");var_dump(strlen(file_get_contents("bug")));';
php -r
'ini_set("memory_limit","-1");var_dump(strlen(file_get_contents("bug",
false, null, 0, 2147483648)));';
Expected result:
----------------
int(2147483648)
int(2147483648)
Actual result:
--------------
hansh@LAPTOP-1PLMKU02 ~
$ rm -r bug; dd if=/dev/null count=0 bs=1 seek=2147483648 of=bug ; php -r
'ini_set("memory_limit","-1");var_dump(strlen(file_get_contents("bug")));'
0+0 records in
0+0 records out
0 bytes copied, 0.0023186 s, 0.0 kB/s
int(2147483648)
hansh@LAPTOP-1PLMKU02 ~
$ rm -r bug; dd if=/dev/null count=0 bs=1 seek=2147483648 of=bug ; php -r
'ini_set("memory_limit","-1");var_dump(strlen(file_get_contents("bug",
false, null, 0, 2147483648)));'0+0 records in
0+0 records out
0 bytes copied, 0.0030518 s, 0.0 kB/s
PHP Warning: file_get_contents(): maxlen truncated from 2147483648 to 2147483647 bytes in Command
line code on line 1
int(2147483647)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80654&edit=1