|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55691 different results from finfo_file and finfo_buffer
Submitted: 2011-09-14 09:35 UTC Modified: 2015-09-13 04:22 UTC
Avg. Score:4.5 ± 0.9
Reproduced:23 of 23 (100.0%)
Same Version:6 (26.1%)
Same OS:3 (13.0%)
From: di_herbert dot huber at yahoo dot com Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 5.3.8 OS: WinXP HE SP2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: di_herbert dot huber at yahoo dot com
New email:
PHP Version: OS:


 [2011-09-14 09:35 UTC] di_herbert dot huber at yahoo dot com
different results from finfo_file and finfo_buffer

1. MS Excel-File stored in mySQL database LONGBLOB-Column
2. This binary data selected from database
3. This binary data stored to tempfile
4. mime-type sniffing done by finfo_buffer on binary data
   > result: application/octet-stream
5. mime-type sniffing done by finfo_file on tempfile
   > result: application/

different result, dependent on used Fileinfo Function

Comment: The tempfile has NO extension like ".xls" that could be used as
hint for mimetype-sniffing

Test script:
      $tempFileName   = tempnam(sys_get_temp_dir(), "tempfile");
      $tempFileHandle = fopen($tempFileName, "w");
      fwrite($tempFileHandle, $attrib);
      // ensure that "extension=php_fileinfo.dll" is enabled in php.ini
      $finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala
mimetype extension
      $fileContentsTypeBuf = finfo_buffer($finfo, $attrib,
      $fileContentsType = finfo_file($finfo, $tempFileName);

Expected result:
same result
"application/" from finfo_buffer
"application/" from finfo_file

Actual result:
different results 
"application/octet-stream" from finfo_buffer
"application/" from finfo_file


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-09-17 07:44 UTC] thomas at partyflock dot nl
Happens to me too, and I experience this for an xls/Excel document too.
 [2015-08-31 18:05 UTC]
-Status: Open +Status: Feedback -Package: Unknown/Other Function +Package: Filesystem function related
 [2015-08-31 18:05 UTC]
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

 [2015-09-13 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2017-08-28 11:43 UTC] magnar at myrtveit dot com
To reproduce this bug:

Download for example the file
Run the following code:

// Change $FilePath to wherever you stored the downloaded file
$FilePath = 'C:/sample.xls';
$Info = new finfo(FILEINFO_MIME_TYPE);
echo $Info->file($FilePath);
echo ' != ';
echo $Info->buffer(file_get_contents($FilePath));

The output will be:
application/ != application/octet-stream

Tested with PHP 7.1 on Windows 10.
 [2017-08-29 15:37 UTC] chealer at gmail dot com
Thanks to Magnar for pointing me here. I reported another variant on Stack Overflow:
My problem also happens with Microsoft Office files, but in my case, the types are application/CDFV2-corrupt vs application/msword.
 [2017-08-29 15:41 UTC] chealer at gmail dot com
In my case too, finfo_file()'s result is superior.

Thanks for reopening
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Mar 01 01:01:27 2021 UTC