Bug #78987 [NEW]: Memory problems running finfo::buffer with PHP_CLI
| From: | jhhillie at amazon dot com | Date: | Wed, 18 Dec 2019 04:12:29 +0000 |
| Subject: | Bug #78987 [NEW]: Memory problems running finfo::buffer with PHP_CLI | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-224374@lists.php.net to get a copy of this message | ||
From: jhhillie at amazon dot com
Operating system: Ubuntu
PHP version: 7.4Git-2019-12-18 (Git)
Package: Performance problem
Bug Type: Bug
Bug description:Memory problems running finfo::buffer with PHP_CLI
Description:
------------
When calling finfo::buffer() with a crafted string, PHP tries to
allocate an insane amount of memory to do so. I found a similar bug here
- https://bugs.php.net/bug.php?id=68819
I suspect the bug may have been re-introduced at some stage during newer
versions.
1) I tested it on the version my customer had been using - v7.0.33
(doesn't work)
2) I then tested on the latest php version - v7.4.0 (doesn't work)
3) Testing on an older version - v5.4.16 it works perfectly.
Test script:
---------------
Generated a random file of 300MB using:
$ sudo fallocate -l 300M test-file
The script used:
<?php
$content = file_get_contents('test-file', true);
$fileInfo = new \finfo(FILEINFO_MIME_TYPE);
var_dump($fileInfo->buffer($content));
?>
Expected result:
----------------
To provide the file metadata (I know there are other ways to do this):
string(19) "application/x-empty"
Actual result:
--------------
PHP Warning: finfo::buffer(): Failed identify data 12:cannot allocate
2516582408 bytes (Cannot allocate memory)application/octet-stream in php
shell code on line 1 bool(false)
--
Edit bug report at https://bugs.php.net/bug.php?id=78987&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78987&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78987&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78987&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78987&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78987&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78987&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78987&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78987&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78987&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78987&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78987&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78987&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78987&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78987&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78987&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78987&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78987&r=mysqlcfg