You are not logged in.

#1 2007-07-12 19:15:03

bart
Member
Registered: 2007-07-12
Posts: 10

incomplete magic file in apache package

Hi,

The magic file (/etc/httpd/conf/magic) is far from complete. For example: jpeg and gif are defined, but png isn't. It describes actually just about 100 different file formats (grep -v ^# magic | sort | uniq | wc -l).

I came to this because my fresh mediawiki installation didn't allow me to upload png images. It took me a while to find out the problem, but it was fun. Just add the following line to /etc/httpd/conf/magic and png images aren't a problem anymore:

# PNG images
> 0     beshort         0x8950          image/png

So, my problem is solved smile

But this hack fixes only this single case; the magic file still lacks a lot of other file formats. Before I switches to Arch, I used Gentoo, so I checked the magic file on my old Gentoo box. Surprisingly the magic files on Arch and Gentoo were exactly equal, but with Gentoo I never had this problem.

The magic file in /etc/httpd/conf is coming from mod_mime_magic, which uses an (very) old version of the magic file from the package called "file". I suppose that the Apache on Gentoo uses the (recent) magic file from the file package, while Arch uses the (old) magic file included in the apache package.

I came up to some questions:
* Why not let apache use the recent (and maintained) magic file from the file package?
* Why not dump the outdated (and not maintained) magic file from the apache packages?

Last edited by bart (2007-07-12 19:31:40)

Offline

#2 2007-07-12 19:36:55

bart
Member
Registered: 2007-07-12
Posts: 10

Re: incomplete magic file in apache package

Yet an other question:
Why not make apache depend on file and replace in /etc/httpd/conf/httpd.conf

#MIMEMagicFile /etc/httpd/conf/magic

by

MIMEMagicFile /usr/share/misc/file/magic

?


[update]This doesn't work[/update]

Last edited by bart (2007-07-13 11:19:27)

Offline

#3 2007-07-13 11:18:55

bart
Member
Registered: 2007-07-12
Posts: 10

Re: incomplete magic file in apache package

Found out a bit more..

Mediawiki has a function called detectMimeType() to find out the mimetype of a file.
First it tries to use finfo_file(). That function is in the CVS version of PHP only.
Next it tries mime_content_type().
If mimecontent_type() fails, it falls back to getimagesize().

To use mime_content_type(), PHP has to be compiled with "--with-mime-magic". mime_content_type() uses independent of MIMEMagicFile in /etc/httpd/conf/httpd.conf the /etc/httpd/conf/magic file. Logical, because it is a PHP thing and has nothing to do with Apache. Thats why changing MIMEMagicFile in /etc/httpd/conf/httpd.conf to "/usr/share/misc/file/magic" doesn't work.

The PHP package for Arch is compiled with "--with-mime-magic", so thats why it uses the deprecated /etc/httpd/conf/magic . On my old Gentoo box it was compiled without, so Mediawiki falls back to getimagesize().

getimagesize() does much more than just figuring out the mimetype, but it knows somehow about PNG.

Offline

#4 2007-07-13 11:31:54

bart
Member
Registered: 2007-07-12
Posts: 10

Re: incomplete magic file in apache package

Adding this line to /etc/php.ini does fix it:

mime_magic.magicfile="/usr/share/misc/file/magic"

Last edited by bart (2007-07-13 11:32:08)

Offline

Board footer

Powered by FluxBB