Bug #80654 [NEW]: file_get_contents() maxlen fails above (2**31)-1 bytes
From: divinity76+spam at gmail dot com
Operating system:
PHP version: 7.3.26
Package: *Directory/Filesystem functions
Bug Type: Bug
Bug description:file_get_contents() maxlen fails above (2**31)-1 bytes
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 bug report at https://bugs.php.net/bug.php?id=80654&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80654&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80654&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80654&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80654&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80654&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80654&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80654&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80654&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80654&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80654&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80654&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80654&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80654&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80654&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80654&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80654&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80654&r=mysqlcfg
Thread (5 messages)
- divinity76+spam at gmail dot com