php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #64793 finfo_open raises warning with env magic file
Submitted: 2013-05-08 18:25 UTC Modified: 2013-05-16 19:29 UTC
From: weierophinney@php.net Assigned: aharvey (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.4.14 OS: Ubuntu 13.04
Private report: No CVE-ID: None
 [2013-05-08 18:25 UTC] weierophinney@php.net
Description:
------------
Using either the system magic file (/usr/share/file/magic.mgc) or the one shipped 
with PHP (http://lxr.php.net/xref/PHP_5_5/ext/fileinfo/tests/magic?
r=12cf930a403d0bbee0c40a5e93554cafd6b0895e), and ensuring that my MAGIC env 
points to the file, any call to finfo_open() that does not specify a MIME file 
raises a warning: "offset `' invalid".

This occurs in 5.3.3 and 5.4.14; I cannot reproduce it in 5.3.21. I've tried a 
variety of magic files, and not yet found one that works reliably across 
versions.

Test script:
---------------
$finfo = finfo_open(FILEINFO_MIME_TYPE);

Expected result:
----------------
(no error)

Actual result:
--------------
finfo_open(): Warning: offset `' invalid

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-05-09 07:50 UTC] ab@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

It's expected that the magic file format change across the libmagic versions. This 
way you may experience some difference even within the same version, libmagic was 
upgraded for 5.4.1 and now again in 5.4.15. The recommended way is to use the 
compiled in magic, passing a magic file from outside you have to care about the 
version compatibility. The same were obviously the experience if you use the file 
commando with different magic file versions.
 [2013-05-09 07:50 UTC] ab@php.net
-Status: Open +Status: Not a bug
 [2013-05-09 13:09 UTC] weierophinney@php.net
After receiving the "answer" to this issue, I decided to run "unset MAGIC" in my 
shell, as the implication is that if you do this, PHP will use its own internal 
magic.mime database. This indeed works.

Unfortunately, the documentation is completely wrong, which is why I never 
determined the correct course of action. It states: 

"Name of a magic database file, usually something like /path/to/magic.mime. If 
not specified, the MAGIC environment variable is used. If this variable is not 
set either, /usr/share/misc/magic is used by default. A .mime and/or .mgc suffix 
is added if needed.

Passing NULL or an empty string will be equivalent to the default value."

Clearly this is incorrect, as the default is actually to use the magic database 
PHP bundles.
 [2013-05-16 19:10 UTC] aharvey@php.net
-Status: Not a bug +Status: Assigned -Type: Bug +Type: Documentation Problem -Package: Filesystem function related +Package: Documentation problem -Assigned To: +Assigned To: aharvey
 [2013-05-16 19:10 UTC] aharvey@php.net
Morphing into a doc bug.

I think this one changed when we started bundling libmagic, as the relevant code appears to be commented out, but I'll check before fixing the manual.
 [2013-05-16 19:28 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&revision=330245
Log: Fix the description of finfo_open()'s behaviour when no magic file or MAGIC
environment variable are provided.

Additionally, improved the wording of the warning and added a note recommending
the use of the bundled magic database, per Matthew's suggestion in the bug
tracker.

Fixes doc bug #64793 (finfo_open raises warning with env magic file).
 [2013-05-16 19:29 UTC] aharvey@php.net
-Status: Assigned +Status: Closed
 [2013-05-16 19:29 UTC] aharvey@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

Turns out this was just plain wrong all along. :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 03:01:28 2024 UTC