Bug #80654 [Asn->Csd]: file_get_contents() maxlen fails above (2**31)-1 bytes
| From: | cmb@php.net | Date: | Mon, 01 Feb 2021 12:01:47 +0000 |
| Subject: | Bug #80654 [Asn->Csd]: file_get_contents() maxlen fails above (2**31)-1 bytes | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-231857@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: Assigned
+Status: Closed
Type: Bug
Package: *Directory/Filesystem functions
PHP Version: 7.3.26
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7e9479083d6dc6d84c393a96eb718bccc0185b9b
Log: Fix #80654: file_get_contents() maxlen fails above (2**31)-1 bytes
Previous Comments:
------------------------------------------------------------------------
[2021-01-28 16:12:48] cmb@php.net
The following pull request has been associated:
Patch Name: Fix #80654: file_get_contents() maxlen fails above (2**31)-1 bytes
On GitHub: https://github.com/php/php-src/pull/6648
Patch: https://github.com/php/php-src/pull/6648.patch
------------------------------------------------------------------------
[2021-01-28 16:09:17] cmb@php.net
The same happens with stream_get_contents().
------------------------------------------------------------------------
[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