ZF-8089: MimeType recognition broken in ZF 1.9.4

Description

When I upload a file and test it against a Zend_Validate_File_MimeType validator, in ZF 1.9.4 I get

Notice: finfo::finfo(): Warning: description `8-bit ISDN mu-law compressed (CCITT G.721 ADPCM voice data enco' truncated in /var/www/ZendFramework-1.9.4-minimal/library/Zend/Validate/File/MimeType.php on line 298

Notice: finfo::finfo(): Warning: description `8-bit ISDN mu-law compressed (CCITT G.721 ADPCM voice data enco' truncated in /var/www/ZendFramework-1.9.4-minimal/library/Zend/Validate/File/MimeType.php on line 298

Notice: finfo::finfo(): Warning: <= not supported in /var/www/ZendFramework-1.9.4-minimal/library/Zend/Validate/File/MimeType.php on line 298

Notice: finfo::finfo(): Warning: <= not supported in /var/www/ZendFramework-1.9.4-minimal/library/Zend/Validate/File/MimeType.php on line 298

Notice: finfo::finfo(): Warning: <= not supported in /var/www/ZendFramework-1.9.4-minimal/library/Zend/Validate/File/MimeType.php on line 298

Notice: finfo::finfo(): Warning: >= not supported in /var/www/ZendFramework-1.9.4-minimal/library/Zend/Validate/File/MimeType.php on line 298

Warning: finfo::finfo(): Failed to load magic database at '/usr/share/file/magic'. in /var/www/ZendFramework-1.9.4-minimal/library/Zend/Validate/File/MimeType.php on line 298

Warning: finfo::file(): The invalid fileinfo object. in /var/www/ZendFramework-1.9.4-minimal/library/Zend/Validate/File/MimeType.php on line 304

Copying the ZF 1.9.3PL1 file Zend/Validate/File/MimeType.php into the 1.9.4 tree allows uploads to validate correctly.

Comments

What php version, Linux- distribution & version are you using? Besides, what is the mimetype of the file you're trying to upload?

Honestly I personally expect this to be a problem with your local installation, given the error you get about /usr/share/file/magic

There were several errors from people who did not set the mimetype database.

Several distributions need to have the database set, and this always lead to problems.

We added a automatic recognition for the database.

As you did not set the database yourself, the validator tries to load it automatically. But it seems that the database it finds within your distribution, is broken.

This is the reason why you are getting this failure.

So there are 2 solutions for you as this is no ZF problem:

*) Repair the broken database at '/usr/share/file/magic'. As you can see all failures are related to this single file.

*) Set the database you want to use manually by giving the related option to the validator.

Closing as non-issue. The found mimetype database is broken.

PS: But you could also use the ini settings or the environment settings to set the correct database to load.

Just FYI, I believe that this is a bug in PHP itself, not ZF. I intend to test again with PHP 5.3.x trunk, but until I get to do that, here are some findings.

The file that fails validation via finfo is validated correctly by /usr/bin/file, so /usr/share/file/magic is NOT broken. Moreover, if I call finfo::__construct and omit the second parameter (magic file), the filetype is detected correctly even by finfo. If I specify the second parameter, I get the same error as in my bug report.

The OS is CentOS 5.3. /usr/share/file/magic is unmodified from the latest RPM, file-4.17-15.el5_3.1

$ file -v file-4.17 magic file from /usr/share/file/magic

$ file -i a1_draft1_20091017224258 a1_draft1_20091017224258: application/msword application/msword

PHP is 5.3.0, as distributed by Remi Collet in an extremely popular CentOS add-on repository, php-5.3.0-2.el5.remi.2 . It is compiled with '--with-mime-magic=/usr/share/file/magic'.