Bug #69214 [ReO->Fbk]: Regression in libmagic magic.mime printf detection
| From: | cmb@php.net | Date: | Tue, 03 Aug 2021 12:39:19 +0000 |
| Subject: | Bug #69214 [ReO->Fbk]: Regression in libmagic magic.mime printf detection | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-235554@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69214&edit=1
ID: 69214
Updated by: cmb@php.net
Reported by: weierophinney@php.net
Summary: Regression in libmagic magic.mime printf detection
-Status: Re-Opened
+Status: Feedback
Type: Bug
Package: Unknown/Other Function
Operating System: Ubuntu 14.10
PHP Version: master-Git-2015-03-10 (Git)
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Is this still an issue with any of the actively supported PHP
versions[1]?
[1] <https://www.php.net/supported-versions.php>
Previous Comments:
------------------------------------------------------------------------
[2016-08-26 13:12:53] cmb@php.net
The package should actually be something like "fileinfo", but that
is not available.
------------------------------------------------------------------------
[2015-03-16 19:29:33] weierophinney@php.net
Except that ext/fileinfo/tests/magic is still in the old format (see https://github.com/php/php-src/blob/master/ext/fileinfo/tests/magic#L4640
for an example). I've literally not been able to find a magic file that doesn't have these
length modifiers.
------------------------------------------------------------------------
[2015-03-12 20:55:51] ab@php.net
libmagic in master was upgraded to a more recent version, the magic file format is not compatible
anymore. For the tests with PHP7 please use some magic from libmagic around 5.20 (just a guess) or
best pull the one located ext/fileinfo/tests/magic in the php source tree.
Thanks.
------------------------------------------------------------------------
[2015-03-10 15:16:28] weierophinney@php.net
Description:
------------
We're testing ZF2 against PHP7 nightly. In the last couple days, we started noticing that our
tests that use a magic.mime file started failing, with messages of the format "finfo_open():
Warning: Printf format
l' is not valid for type lequad' in description
`...'".
From what I can see, recent changes to ext/fileinfo/libmagic/ have removed support for the following
printf sequences:
* l, ll, h, and hh (used as length modifiers)
* .0 (used to indicate zero-padding vs space padding)
* numeric precision
This is particularly problematic, as the lequad and bequad libmagic specifications require specific
formats that require such modifiers, and without the above, there is no way to provide a valid
magic.mime file to finfo_open(). Researching libmagic, I cannot find a magic.mime file that does NOT
have these formats present.
Test script:
---------------
<?php
$magicData = file_get_contents('https://raw.githubusercontent.com/zendframework/zf2/2750340ad353cad9e80525d1c13efcda03e21027/tests/ZendTest/Validator/File/_files/magic.mime');
$magicFile = tempnam(sys_get_temp_dir(), 'mag');
file_put_contents($magicFile, $magicData);
finfo_open(FILEINFO_MIME_TYPE, $magicFile);
Actual result:
--------------
ErrorException: finfo_open(): Failed to load magic database at '...'.
Caused by
ErrorException: finfo_open(): Warning: Printf format h' is not valid for type
leshort' in description `.%hd'
// and many, many more similar errors
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69214&edit=1