Bug #61940 [Com]: filinfo fails when loading external magic database
| From: | signe at cothlamadh dot net | Date: | Wed, 08 Aug 2012 19:41:46 +0000 |
| Subject: | Bug #61940 [Com]: filinfo fails when loading external magic database | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-172509@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61940&edit=1
ID: 61940
Comment by: signe at cothlamadh dot net
Reported by: sean@php.net
Summary: filinfo fails when loading external magic database
Status: Not a bug
Type: Bug
Package: Unknown/Other Function
Operating System: Linux (but probably everywhere)
PHP Version: 5.3.12
Assigned To: ab
Block user comment: N
Private report: N
New Comment:
For some reason this problem is also appearing in Ubuntu Precise's version of 5.3.10. It
appears that the patch may have been backported, and that's causing issues because it
doesn't match the 5.3.11 warnings... and Ubuntu Precise bundles libmagic 5.09-2.
Previous Comments:
------------------------------------------------------------------------
[2012-06-29 09:38:29] ab@php.net
documentation adopted for now
------------------------------------------------------------------------
[2012-05-04 21:11:42] ab@php.net
I agree, that's annoying side effect in a minor release. But security comes first, that was in
mind. Plus, libmagic 5.11 is the latest and as such it's future safe for php.
I think fixing that notices is a very good idea. I'll take a look at the libmagic. May be there
is some sort of lint for a magic file, so it could be checked before loading. Or, it could just stop
when it gets the first error.
That's only a time question for me. If someone came to that earlier, a patch would be
appretiatecd :)
------------------------------------------------------------------------
[2012-05-04 19:10:23] sean@php.net
It's too late now, but this should not have happened in a point release of PHP, in my opinion.
At the very least, I think the banquet of Notices should be trapped and handled more intelligently
with probably one Warning (or even Fatal; finfo (NULL) is useless in this state).
"PHP Notice: finfo::finfo(): Warning: offset `?' invalid" is not useful.
------------------------------------------------------------------------
[2012-05-04 18:09:33] ab@php.net
The libmagic on which fileinfo ext relies was upgraded from 5.04 to 5.11, that's a big jump. In
the squeeze (using 5.04) only the security patch was applied, where the actual fix was done on 5.11
(debian testing afaik). In the libmagick at least 5.11 (not sure where it starts) not only the
database was changed, but also the way the lib parses it, resulting any older database being
incompatible with the current fileinfo.
But, the 5.11 database is compiled into the fileinfo, so there is no need to use any externals. And
I'm afraid there is no way back. If you really must use an external libmagic database for some
reasons, I'd suggest you to take file-5.11 distribution, make it and you'll have exactly
the same magic file, which is compiled in. Or you could steal a newer magic file from some newer
distro, that would work too. Running the same code with different php versions would merely need
your workaround.
------------------------------------------------------------------------
[2012-05-04 17:08:35] sean@php.net
FWIW, this workaround allows our code to functionâ¦
if (version_compare(PHP_VERSION, '5.3.11') >= 0) {
$magicfile = 'magic_php-gte-5_3_11.mgc';
} else {
$magicfile = 'magic_php-lt-5-3-11.mgc';
}
$magicpath = __DIR__ . "/../../../config/{$magicfile}";
Where we use both our old magic DB (the one from Ubuntu/Debian), and the one bundled here: https://raw.github.com/php/php-src/master/ext/fileinfo/tests/magic
(I haven't found a way to use one database with both versions.)
------------------------------------------------------------------------
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=61940
--
Edit this bug report at https://bugs.php.net/bug.php?id=61940&edit=1