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

 ID:                 61940
 Updated by:         a...@php.net
 Reported by:        s...@php.net
 Summary:            filinfo fails when loading external magic database
-Status:             Assigned
+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:

documentation adopted for now


Previous Comments:
------------------------------------------------------------------------
[2012-05-04 21:11:42] a...@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] s...@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] a...@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] s...@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.)

------------------------------------------------------------------------
[2012-05-04 16:22:21] s...@php.net

Also, this seems to be caused by the changes to
https://github.com/php/php-src/tree/master/ext/fileinfo/libmagic
in
https://github.com/php/php-src/commit/12cf930a403d0bbee0c40a5e93554cafd6b0895e
which references
https://bugs.php.net/61504

Sure, it's good to fix security problems, but this also breaks code that uses 
an external database… in a minor point release.

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


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

Reply via email to