php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64684 FILEINFO_MIME_ENCODING fail
Submitted: 2013-04-20 14:28 UTC Modified: 2013-04-22 11:10 UTC
From: rg at mejoramos dot com Assigned: ab (profile)
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 5.3.24 OS: Windoqs and Linux
Private report: No CVE-ID: None
 [2013-04-20 14:28 UTC] rg at mejoramos dot com
Description:
------------
If FILE have contain exactly the string:
"0"
without quotes, then:

in Windows output:
Warning: finfo_file(): Failed identify data 0:(null) in ...

in Linux output:
Warning: finfo_file() [function.finfo-file]: Failed identify data 0:(null) in ...

Why file have a "0" ?
becouse I need read a integer in range 0-25 to take some decisions...

Why I run finfo_file() ?
Becouse I need know if last edition create UTF8 or ISO-8859-1



Test script:
---------------
echo 'Encoding: '.finfo_file($finfo,$_FILES['name_in_FORM']['tmp_name'],FILEINFO_MIME_ENCODING);

Remember: target file contain only the string: "0" without quotes.


Patches

put_a_AT_in_start_of_line (last revision 2013-04-20 14:36 UTC by rg at mejoramos dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-04-21 16:28 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2013-04-21 16:28 UTC] ab@php.net
I can't reproduce this using your snippet, I get us-ascii and that will be it in any case. For that I've created a file containing just 0. 

And, you might anyway be interested on the next 5.4 release as libmagic was upgraded, or already test the latest windows snapshot from http://windows.php.net/downloads/snaps/php-5.4/ .

To reproduce this issue a reliable snippet in required.
 [2013-04-21 16:29 UTC] ab@php.net
-Assigned To: +Assigned To: ab
 [2013-04-21 17:38 UTC] rg at mejoramos dot com
Thanks by you interest.

You can see ALL DETAIL by download:

http://utp.guirv.com/descargas/?f=/PHP_BUG_64684.rar
(318 bits)

When you run in Windows:
Warning: finfo_file(): Failed identify data 0:(null) in E:\HTTP... ...\PHP_BUG_64684\fileinfo.php on line 3 

When you run in Linux CentOs:
 Warning: finfo_file() [function.finfo-file]: Failed identify data 0:(null) in /home/... .../PHP_BUG_64684/fileinfo.php on line 3
 [2013-04-22 07:31 UTC] ab@php.net
Thanks for reporting this. Now I get the behavior you've described. You literally put only one char 0x30 into the file, and that's exactly the issue. Previously I've tested with a kind of file created manually, but an editor automatically appends some chars there. So to get such a case on has to create it with a hex editor or just php -r 'file_put_contents("file", "0")'; 

I'd consider this one as not a bug. If I run "file action_number" with your file on the Linux shell, here's the output:

action_number: very short file (no magic)

Running "file --mime --mime-encoding action_number"  says

action_number: application/octet-stream

which is a normal fallback.

Thus - the file is way too short, and that's the issue. libmagic needs at least a few bytes at the start of a file to do the magic.

For your case - if you know there's only a number in that file, no need to check the charset. It'll be always ascii. Either it's a number which you read in and cast integer, or it's invalid - I'd do so.
 [2013-04-22 07:31 UTC] ab@php.net
-Status: Feedback +Status: Not a bug
 [2013-04-22 10:22 UTC] rg at mejoramos dot com
Thanks by you help.

>>>the file is way too short, and that's the issue.
>>>libmagic needs at least a few bytes at the start of a file to do the magic.

Mmm...

If you remove the number (if file is EMPTY), then PHP don´t cry.

Conclution:
The issue is more than of Magic, and no of PHP ¿?
 [2013-04-22 11:10 UTC] ab@php.net
Almost yes. Please note that we just wrap libmagic with php, the file command is yet another wrapper. I also can see the same warning with 5.5 branch on an empty file, where with the file command it's the same "file too small" warning. So looks better there, but that are indeed edge cases handled by libmagic, not php.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 15:01:28 2024 UTC