Bug 177926 - mime_content_type returns text/plain for png files
mime_content_type returns text/plain for png files
Product: Fedora
Classification: Fedora
Component: php (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Joe Orton
David Lawrence
Depends On:
  Show dependency treegraph
Reported: 2006-01-16 09:59 EST by Doncho N. Gunchev
Modified: 2008-05-06 11:33 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2008-05-06 11:33:16 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
proposed fix (375 bytes, patch)
2007-01-12 18:34 EST, Kir Kolyshkin
no flags Details | Diff
proposed fix (correct) (380 bytes, patch)
2007-01-12 18:43 EST, Kir Kolyshkin
no flags Details | Diff

  None (edit)
Description Doncho N. Gunchev 2006-01-16 09:59:20 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8) Gecko/20051111 Firefox/1.5

Description of problem:
In FC4 mime_content_type returns bad MIME (text/plain) for png files. I tested this with FC3 and it works fine.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Install FC4
2. Update
3. php -r 'print("[" . mime_content_type("blank-ico64.png") . "]\n");'

Actual Results:  [text/plain]

Expected Results:  [image/png]

Additional info:
Comment 1 Sorin Sbarnea 2006-03-01 10:00:39 EST
I confirm this bug.
Comment 2 Kir Kolyshkin 2007-01-12 18:29:40 EST
Bad news: the bug is still not fixed in FC5 and even FC6. I have just checked both.

Even more bad news: this PHP function (i.e. mime_content_type) is used in
Mediawiki to check the image file while it is being uploaded to wiki -- and this
bug makes it unable to upload PNG files to mediawiki installed on FC4/5/6 system
-- it's a pity and it's a shame.

Good news: the fix is one-liner to spec file:
--- php.spec.mime       2007-01-13 02:24:30.000000000 +0300
+++ php.spec    2007-01-13 02:23:37.000000000 +0300
@@ -421,7 +421,7 @@
        --enable-calendar \
        --enable-dbx \
        --enable-dio \
-        --with-mime-magic=%{_sysconfdir}/httpd/conf/magic \
+        --with-mime-magic=%{_datadir}/file/magic \
         --without-sqlite \
         --with-libxml-dir=%{_prefix} \
        --with-xml \

Details: without this patch, mime_content_type uses Apache's magic file, which
is _much_ times shorter than that of file(1) utility and does not contain any
magic for PNG files. By reverting to use file's magic file, this is fixed. I
though it is also needed to add requirements for "file", but it's already there
in spec -- so I suppose file's magic was used some time before...

Hope I made it clear enough to finally fix this nasty bug.
Comment 3 Kir Kolyshkin 2007-01-12 18:31:25 EST
Bug is valid for FC6 as well, so please change "version" accordingly -- since I
don't have permission to.
Comment 4 Kir Kolyshkin 2007-01-12 18:34:22 EST
Created attachment 145497 [details]
proposed fix
Comment 5 Kir Kolyshkin 2007-01-12 18:43:43 EST
Created attachment 145502 [details]
proposed fix (correct)

I'm sorry, previous attachment and patch in comment #2 is wrong. Correct patch
is attached, correct fix is the following:
-	 --with-mime-magic=%{_sysconfdir}/httpd/conf/magic \
+	 --with-mime-magic=%{_datadir}/file/magic.mime \

Please note that magic.mime file (from file(1) utility) is only about two times
larger than magic file (from Apache), so it should not create any additional
overhead or smth.

I have also checked php behavior on RHEL4 (actually CentOS4) -- php reads
/usr/share/file/magic.mime there (i.e. same as after my patch).
Comment 6 Doncho N. Gunchev 2007-03-20 14:07:31 EDT
For images getimagesize() can be used as a workaround, but a real fix would be
better (c'mon, png is not that rare file type). Should this bug be reported
Comment 7 Doncho N. Gunchev 2007-03-20 14:22:37 EDT
In latest FC6 updates (now, 2007-03-20) the example returns empty string, not
text/plain. Also it segfault-ed on one jpeg and recognized only text/plain,
text/html - no video, sound, document was recognized (they seem to exist in
apache's mime file) except some that got text/plain. Swapping
/usr/share/file/magic.mime to /etc/httpd/conf/mime did nothing more, so the
problem is not the mime file that ships with apache.
Someone willing to look if PHP has this bug reported?
Comment 8 Doncho N. Gunchev 2007-03-20 14:24:42 EDT
Quick and easy check:
for i in *; do [ -f "$i" ] && echo -n "$i: " && php -r 'print("[" .
mime_content_type("'"$i"'") . "]\n");'; done
Comment 9 Joe Orton 2007-03-21 06:16:51 EDT
The extension is deprecated upstream in favour of PECL::Fileinfo.

Did the change to use /usr/share/file/magic.mime in the latest updates make
things worse or better?
Comment 10 Doncho N. Gunchev 2007-04-21 16:38:33 EDT
No for me, I have file-4.19-2.fc6 and even after manual change of the magic file
[ cd /etc/httpd/conf; mv magic magic.dist ln -s /usr/share/file/magic.mime magic
] my example from comment #8 does not recognize a single graphical file I have.

php-pecl-Fileinfo is in extras, but I had to download the source to see how it
works, thanks for the info. This bug was not present in FC1 (at least), but
don't downgrade php/apache, please ;-)
Comment 11 petr dudka 2007-05-06 12:18:43 EDT
phpinfo() show '--with-mime-magic=/usr/share/file/magic' on fedora6.
so, this path wrong and NOT /etc/httpd/conf/magic and i can't copy
/usr/share/file/magic.mime to /usr/share/file/magic because i think some other
software will work wrong. 

Comment 12 Doncho N. Gunchev 2008-03-04 19:53:47 EST
It's too late for FC6 and this function is missing from php-5.2.5-2.fc8.
Can't/Won't fix?
Comment 13 Bug Zapper 2008-04-03 22:06:47 EDT
Fedora apologizes that these issues have not been resolved yet. We're
sorry it's taken so long for your bug to be properly triaged and acted
on. We appreciate the time you took to report this issue and want to
make sure no important bugs slip through the cracks.

If you're currently running a version of Fedora Core between 1 and 6,
please note that Fedora no longer maintains these releases. We strongly
encourage you to upgrade to a current Fedora release. In order to
refocus our efforts as a project we are flagging all of the open bugs
for releases which are no longer maintained and closing them.

If this bug is still open against Fedora Core 1 through 6, thirty days
from now, it will be closed 'WONTFIX'. If you can reporduce this bug in
the latest Fedora version, please change to the respective version. If
you are unable to do this, please add a comment to this bug requesting
the change.

Thanks for your help, and we apologize again that we haven't handled
these issues to this point.

The process we are following is outlined here:

We will be following the process here:
http://fedoraproject.org/wiki/BugZappers/HouseKeeping to ensure this
doesn't happen again.

And if you'd like to join the bug triage team to help make things
better, check out http://fedoraproject.org/wiki/BugZappers
Comment 14 Bug Zapper 2008-05-06 11:33:14 EDT
This bug is open for a Fedora version that is no longer maintained and
will not be fixed by Fedora. Therefore we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen thus bug against that version.

Thank you for reporting this bug and we are sorry it could not be fixed.

Note You need to log in before you can comment on or make changes to this bug.