Bug #69224 [NEW]: Fileinfo tries to allocate huge amounts of memory for some text files
From: john at zerocrates dot org
Operating system: Linux
PHP version: 5.6.6
Package: Filesystem function related
Bug Type: Bug
Bug description:Fileinfo tries to allocate huge amounts of memory for some text files
Description:
------------
When run on certain files (chiefly text files and in this specific
instance, CSV files), the Fileinfo extension immediately tries to
allocate a huge amount of memory (multiple gigabytes) and exceeds the
limit.
This behavior on a sample file was confirmed on multiple PHP versions
across different distributions, including PHP 5.4.36 on CentOS (with
"file" version 5.04) and PHP 5.6.6 on Gentoo (with "file" version
5.22).
The file "test.csv" that causes this behavior is available at
http://zerocrates.org/test.csv
Test script:
---------------
$finfo = finfo_open(FILEINFO_MIME_TYPE);
echo finfo_file($finfo, 'test.csv');
OR
$finfo = new finfo(FILEINFO_MIME_TYPE);
echo $finfo->file('test.csv');
Expected result:
----------------
The output should simply be "text/plain"
Running the command-line tool "file -bi" on the sample file gives a
correct output more or less immediately: "text/plain; charset=us-ascii"
Actual result:
--------------
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to
allocate 4294955358 bytes)
Note the amount of bytes for the attempted allocation, 4 gigabytes.
--
Edit bug report at https://bugs.php.net/bug.php?id=69224&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69224&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69224&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69224&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69224&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69224&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69224&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69224&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69224&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69224&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69224&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69224&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69224&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69224&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69224&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69224&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69224&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69224&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69224&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69224&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69224&r=mysqlcfg
Thread (7 messages)
- john at zerocrates dot org