php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80654 file_get_contents() maxlen fails above (2**31)-1 bytes
Submitted: 2021-01-22 02:35 UTC Modified: 2021-01-28 16:09 UTC
From: divinity76+spam at gmail dot com Assigned: cmb (profile)
Status: Closed Package: *Directory/Filesystem functions
PHP Version: 7.3.26 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: divinity76+spam at gmail dot com
New email:
PHP Version: OS:

 

 [2021-01-22 02:35 UTC] 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)


Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-28 16:09 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2021-01-28 16:09 UTC] cmb@php.net
The same happens with stream_get_contents().
 [2021-01-28 16:12 UTC] 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-02-01 12:01 UTC] cmb@php.net
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
 [2021-02-01 12:01 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC