|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69214 Regression in libmagic magic.mime printf detection
Submitted: 2015-03-10 15:16 UTC Modified: 2021-08-03 13:25 UTC
From: Assigned: cmb (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: master-Git-2015-03-10 (Git) OS: Ubuntu 14.10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2015-03-10 15:16 UTC]
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:
$magicData = file_get_contents('');
$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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-12 20:55 UTC]
-Status: Open +Status: Not a bug
 [2015-03-12 20:55 UTC]
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.

 [2015-03-16 19:29 UTC]
-Status: Not a bug +Status: Re-Opened
 [2015-03-16 19:29 UTC]
Except that ext/fileinfo/tests/magic is still in the old format (see for an example). I've literally not been able to find a magic file that doesn't have these length modifiers.
 [2016-08-26 13:12 UTC]
-Package: Filesystem function related +Package: Unknown/Other Function
 [2016-08-26 13:12 UTC]
The package should actually be something like "fileinfo", but that
is not available.
 [2021-08-03 12:39 UTC]
-Status: Re-Opened +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-08-03 12:39 UTC]
Is this still an issue with any of the actively supported PHP

[1] <>
 [2021-08-03 13:22 UTC]
To my knowledge, this is resolved; we've been testing ZF and Laminas successfully for years now.
 [2021-08-03 13:25 UTC]
-Status: Feedback +Status: Closed
 [2021-08-03 13:25 UTC]
Thanks for the swift reply!  I'm closing then.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 30 16:01:33 2024 UTC