Bug #67516 [Opn]: wrong mimetypes with finfo_file(filename, FILEINFO_MIME_TYPE)

From: Date: Wed, 07 Sep 2016 09:31:37 +0000
Subject: Bug #67516 [Opn]: wrong mimetypes with finfo_file(filename, FILEINFO_MIME_TYPE)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203846@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67516&edit=1

 ID:                 67516
 User updated by:    spam2 at rhsoft dot net
 Reported by:        spam2 at rhsoft dot net
 Summary:            wrong mimetypes with finfo_file(filename,
                     FILEINFO_MIME_TYPE)
 Status:             Open
 Type:               Bug
 Package:            Filesystem function related
 Operating System:   Linux
 PHP Version:        7.0.11
 Block user comment: N
 Private report:     N

 New Comment:

well, in a perfect world on would be able to update 'data_file.c' with the script in the
source tree before compile PHP, in the real world the file is updates, php builds but it don't
work

what about someone takes afte rmore than a year a look why https://access.thelounge.net/harry/php-mimetype-bug.gif
is recognized as application/octet-stream instead image/gif and considers to update the mime
database?

i don't get all the excuses for not use the system libmagic - for open_basedir and
streams-support one would need nothing else than a tiny wrapper doing that all with a tempfile which
ins finally feeded to the system libmagic instead fork it completly

_______________________________________

%prep
%setup -q -n php-%{version}
%patch1 -p1

# generate 'data_file.c' from bundeled libmagic with current system data
/usr/bin/php ext/fileinfo/create_data_file.php /usr/share/misc/magic.mgc >
ext/fileinfo/data_file.c
_______________________________________

[harry@rh:/data/lounge-daten/php-mimtype-bug]$ php mime.php
/mnt/data/lounge-daten/php-mimtype-bug/1.gif
/usr/bin/file -b --mime-type
image/gif

finfo_file(filename, FILEINFO_MIME_TYPE)

Warning: finfo_open(): Failed to load magic database at '(null)'. in
/mnt/data/lounge-daten/php-mimtype-bug/mime.php on line 15

Warning: finfo_file() expects parameter 1 to be resource, boolean given in
/mnt/data/lounge-daten/php-mimtype-bug/mime.php on line 16


Warning: finfo_close() expects parameter 1 to be resource, boolean given in
/mnt/data/lounge-daten/php-mimtype-bug/mime.php on line 17


Previous Comments:
------------------------------------------------------------------------
[2016-09-06 20:21:13] spam2 at rhsoft dot net

libmagic: 522
file-5.25-6.fc24.x86_64

file-5.22-1.fc21  2015-02-10 06:52:41
file-5.25-6.fc24  2016-02-03 22:20:33

and there where redhat bugfixes in the meantime about wrong detected files (some of them reported by
me) PHP never has seen

------------------------------------------------------------------------
[2016-09-06 20:09:36] spam2 at rhsoft dot net

well, if it would be reasonable updated or at lest support the systems magic-data, with PHP
7.0.11RC1 still the same bugs as 2 years ago

[harry@srv-rhsoft:/data/lounge-daten/php-mimtype-bug]$ php mime.php
/mnt/data/lounge-daten/php-mimtype-bug/1.gif
/usr/bin/file -b --mime-type
image/gif

finfo_file(filename, FILEINFO_MIME_TYPE)
application/octet-stream

------------------------------------------------------------------------
[2015-07-13 11:47:21] nikic@php.net

@rhsoft PHP uses a patched libmagic primarily to a) integrate with PHP filesystem APIs, including
things like stream wrappers, but more importantly also open_basedir restrictions etc and b) to use
our per-request allocator. If you're interested in what the differences are, have a look at https://github.com/php/php-src/blob/master/ext/fileinfo/libmagic.patch.

------------------------------------------------------------------------
[2015-07-13 11:25:42] spam2 at rhsoft dot net

as said i build PHP from the unpatched upstream sources, so the libmagic is bundeled and that exists
from 5.5.13 until 5.6.11 while the file-package from Fedora (cli command file) recognizes it
correctly, hence i even wrote admin scripts calling the file-cli from PHP 

the problem is that at least for Fedora the distributions file-package becomes often updates in case
of bugs and wrong recognized samples and PHP is always behind :-(

------------------------------------------------------------------------
[2015-07-13 11:17:39] cmb@php.net

Thanks for making the file available, and sorry for the bad
pointer to picpaste.com.

Anyhow, a quick check:

    cmb@debian64:~$ file -b --mime-type 67516.gif
    application/octet-stream
    cmb@debian64:~$ dpkg -s file
    Package: file
    Status: install ok installed
    Priority: standard
    Section: utils
    Installed-Size: 119
    Maintainer: Christoph Biedl <debian.axhn@manchmal.in-ulm.de>
    Architecture: amd64
    Multi-Arch: foreign
    Version: 1:5.22+15-2
    Depends: libc6 (>= 2.4), libmagic1 (= 1:5.22+15-2), zlib1g (>= 1:1.1.4)
    Description: Determines file type using "magic" numbers
     File tests each argument in an attempt to classify it. There are
     three sets of tests, performed in this order: filesystem tests,
     magic number tests, and language tests. The first test that
     succeeds causes the file type to be printed.
    Homepage: http://www.darwinsys.com/file/
    
Which version of file/libmagic do you use?

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=67516


--
Edit this bug report at https://bugs.php.net/bug.php?id=67516&edit=1


Thread (30 messages)

« previous php.bugs (#203846) next »