Bug #71562 [NEW]: fileinfo cannot load distro-provided magic files
| From: | david dot nielson at cpanel dot net | Date: | Tue, 09 Feb 2016 21:06:49 +0000 |
| Subject: | Bug #71562 [NEW]: fileinfo cannot load distro-provided magic files | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-199141@lists.php.net to get a copy of this message | ||
From: david dot nielson at cpanel dot net
Operating system: Debian Sid; CentOS 6; CentOS 7
PHP version: 7.0.3
Package: Filesystem function related
Bug Type: Bug
Bug description:fileinfo cannot load distro-provided magic files
Description:
------------
Steps to reproduce:
- Download and compile PHP 7.0.3 from php.net
- Edit attached script to point to the magic file on your system
(comments should help)
- run script through PHP 7 binary
- observe unhandled exception
- run script through PHP 5.x
- observe success messages
Additional information:
using strace, I determined that PHP is opening and reading at least some
data from the magic file before throwing an exception. I could not see
any information from strace to indicate what the problem might be,
though.
The exception doesn't say *why* the file couldn't be loaded, and I don't
know how I would get more information about the nature of the exception.
All I can prove is that it's not ENOENT.
Test script:
---------------
<?php
// http://us3.php.net/manual/en/book.fileinfo.php
// CentOS keeps its magic file here
$magic_file = '/usr/share/misc/magic';
// Debian keeps its magic file here
$magic_file = '/usr/share/file/magic';
$finfo = new finfo(FILEINFO_MIME, $magic_file);
if($finfo) {
echo "0 fileinfo: create finfo object\n"; } else {
echo "1 fileinfo: create finfo object failed\n";
die;
}
$type = $finfo->file(__FILE__);
if($type) {
echo "0 fileinfo: read file type: $type\n"; } else {
echo "1 fileinfo: read file type failed\n";
}
?>
Expected result:
----------------
Running the script through PHP 5.x returns:
0 fileinfo: create finfo object
0 fileinfo: read file type: text/x-php; charset=us-ascii
Actual result:
--------------
0 fileinfo: extension is loaded
Fatal error: Uncaught Exception: finfo::finfo(): Failed to load magic
database at '/home/david/code/php/magic'. in
/home/david/code/php/php_module_fileinfo.php:35
Stack trace:
#0 /home/david/code/php/php_module_fileinfo.php(35): finfo->finfo(1040,
'/home/david/cod...')
#1 {main}
thrown in /home/david/code/php/php_module_fileinfo.php on line 35
--
Edit bug report at https://bugs.php.net/bug.php?id=71562&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71562&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71562&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71562&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71562&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71562&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71562&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71562&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71562&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71562&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71562&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71562&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71562&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71562&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71562&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71562&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71562&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71562&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71562&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71562&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71562&r=mysqlcfg