Bug #71562 [Asn->Nab]: fileinfo cannot load distro-provided magic files
| From: | ab@php.net | Date: | Thu, 24 Nov 2016 15:02:55 +0000 |
| Subject: | Bug #71562 [Asn->Nab]: fileinfo cannot load distro-provided magic files | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-205610@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71562&edit=1
ID: 71562
Updated by: ab@php.net
Reported by: david dot nielson at cpanel dot net
Summary: fileinfo cannot load distro-provided magic files
-Status: Assigned
+Status: Not a bug
Type: Bug
Package: Filesystem function related
Operating System: Debian Sid; CentOS 6; CentOS 7
PHP Version: 7.0.3
Assigned To: remi
Block user comment: N
Private report: N
New Comment:
See bug #66885.
Thanks.
Previous Comments:
------------------------------------------------------------------------
[2016-08-02 09:27:00] remi@php.net
When "libmagic" change, the format of the magic file sometime also change.
This the reason why PHP use a bundled copy.
------------------------------------------------------------------------
[2016-02-10 11:07:25] pajoye@php.net
Remi, could you take a look please?
------------------------------------------------------------------------
[2016-02-09 21:06:44] david dot nielson at cpanel dot net
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 this bug report at https://bugs.php.net/bug.php?id=71562&edit=1