php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71562 fileinfo cannot load distro-provided magic files
Submitted: 2016-02-09 21:06 UTC Modified: 2016-11-24 15:03 UTC
Votes:3
Avg. Score:4.0 ± 0.8
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: david dot nielson at cpanel dot net Assigned: remi (profile)
Status: Duplicate Package: Filesystem function related
PHP Version: 7.0.3 OS: Debian Sid; CentOS 6; CentOS 7
Private report: No CVE-ID: None
 [2016-02-09 21:06 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-02-10 11:07 UTC] pajoye@php.net
-Assigned To: +Assigned To: remi
 [2016-02-10 11:07 UTC] pajoye@php.net
Remi, could you take a look please?
 [2016-08-02 09:27 UTC] 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-11-24 15:02 UTC] ab@php.net
-Status: Assigned +Status: Not a bug
 [2016-11-24 15:02 UTC] ab@php.net
See bug #66885.

Thanks.
 [2016-11-24 15:03 UTC] ab@php.net
-Status: Not a bug +Status: Duplicate
 [2016-11-24 15:03 UTC] ab@php.net
change to duplicate.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC