php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77784 mime_content_type result gets doubled for xlsx
Submitted: 2019-03-23 10:29 UTC Modified: 2024-05-24 21:41 UTC
Votes:112
Avg. Score:4.4 ± 0.8
Reproduced:110 of 111 (99.1%)
Same Version:32 (29.1%)
Same OS:79 (71.8%)
From: dpoddubny at gmail dot com Assigned: nielsdos (profile)
Status: Closed Package: Filesystem function related
PHP Version: 7.3.3 OS: linux
Private report: No CVE-ID: None
 [2019-03-23 10:29 UTC] dpoddubny at gmail dot com
Description:
------------
Hello. Starting from php 7.3.2 function mime_content_type doubles the result for xlsx files created in LibreOffice (6.0.7.3). While php 7.3.1 works correctly.


Test script:
---------------
How to reproduce:
1. git clone https://github.com/karser/php_bug_mime_content_type_doubles_result

2. Build the image and see the bug:

docker build --no-cache --build-arg PHP_VER=7.3.2 .

Step 5/5 : RUN php -r "var_dump(mime_content_type('/test.xlsx'));"
 ---> Running in 71f6655ae0ed
string(130) "application/vnd.openxmlformats-officedocument.spreadsheetml.sheetapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet"


docker build --no-cache --build-arg PHP_VER=7.3.1 .

Step 5/5 : RUN php -r "var_dump(mime_content_type('/test.xlsx'));"
 ---> Running in 27e744a45920
string(65) "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"


Expected result:
----------------
mime_content_type('/test.xlsx') returns "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

Actual result:
--------------
mime_content_type('/test.xlsx') returns "application/vnd.openxmlformats-officedocument.spreadsheetml.sheetapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-17 15:42 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2019-04-17 15:42 UTC] cmb@php.net
I can reproduce this with the provided .xlsx, but not with
arbitrary LibreOffice .xlsx files.  The behavioral change is most
likely caused by the upgrade to 5.34[1].

[1] <http://git.php.net/?p=php-src.git;a=commit;h=d874d4a15c2e17a753d580691906c95e9153b823>
 [2019-04-23 08:51 UTC] hrvoje dot novosel at gmail dot com
Just to add another note, I've hit this issue today with php 7.3.4
I've also tried resaving the xlsx with LibreOffice 6.1.5.2 (x64) and after that I get application/octet-stream as function return.
 [2019-12-06 10:23 UTC] krihog at gmail dot com
Encountered this issue a couple of days ago when trying an upgrade to PHP 7.4.0
With xlsx-files downloaded from Google Sheets.
 [2020-01-07 14:54 UTC] albsmul at gmail dot com
Same problem with php 7.4.1 and a Word docx file (libmagic 537) - mime_content_type returns "application/vnd.openxmlformats-officedocument.wordprocessingml.documentapplication/vnd.openxmlformats-officedocument.wordprocessingml.document"

Worked well on old php 5.6.26 (libmagic 517)
 [2020-03-13 10:26 UTC] mcorteel at yahoo dot fr
Same problem with LibreOffice 6.0.7.3 and PHP 7.4.2.
Mimetype: application/vnd.openxmlformats-officedocument.spreadsheetml.sheetapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet
 [2020-03-26 12:45 UTC] willem at soomedia dot nl
I'm experiencing the same issue in my Docker container with PHP version 7.3.11.
 [2020-05-13 20:24 UTC] oziranhua at instructure dot com
This also is affecting word documents.

Tested with:
- MAC OS 10.15.4/ PHP 7.3.4
- Ubuntu 16.04.6 LTS / PHP 7.3.13
- Ubuntu 16.04.6 LTS / PHP 7.3.14


$ file --mime-type test.docx
test.docx: application/vnd.openxmlformats-officedocument.wordprocessingml.document
$ php -a
Interactive shell

php > print mime_content_type('./test.docx');
application/vnd.openxmlformats-officedocument.wordprocessingml.documentapplication/vnd.openxmlformats-officedocument.wordprocessingml.document
 [2020-05-14 09:13 UTC] michael at roth dot red
I got the same issue with finfo(FILEINFO_MIME_TYPE, $file) in php 7.4.5 on linux
 [2020-05-18 00:10 UTC] ryanmcquerry at gmail dot com
I am seeing this duplication with docx files downloaded from Google Docs.  When I open them in Word and do a "Save As", it works again.
 [2020-05-28 14:53 UTC] alexeyseliverstov dot dev at gmail dot com
Similar to what ryanmcquerry reported, if you open and save your xslx file in Excel, it also solves the problem. That's a good enough workaround for the time being, while the bug is not fixed.
 [2020-06-09 17:37 UTC] juansmrad at gmail dot com
I experience this issue with PHP 7.4.6 on Ubuntu 20 using docx format. I've tried opening and saving it from office365 but that did not solve it.
 [2021-05-11 09:00 UTC] yannick dot mauray at arcantel dot ch
We encountered this problem on php 7.3.11, on FreeBSD 12.0, with some XLSX and DOCX files.
Is there an update or a workaround ? Or a scheduled patch maybe ?
 [2021-06-21 17:48 UTC] charles at fullsteamlabs dot com
Encountered this using PHP 7.4.19 both inside a docker container and 7.3 (don't have more specific info) on the Pantheon hosting platform. 

Confirmed that the mime type returned by

    $finfo     = finfo_open( FILEINFO_MIME_TYPE );
    $real_mime = finfo_file( $finfo, $file );

is `application/vnd.openxmlformats-officedocument.wordprocessingml.documentapplication/vnd.openxmlformats-officedocument.wordprocessingml.document` for a docx file that was exported from Google Drive. 

This problem did not occur with a docx file created in LibreOffice.
 [2021-08-17 21:21 UTC] gilbertpaquin1995 at gmail dot com
I got the same issue with PHP 8.0.3 and PHP 8.0.6 on Windows and Linux
 [2021-12-20 09:39 UTC] cmb@php.net
This looks like an issue in libmagic?  Has it been reported
upstream[1], or has it been resolved there already?

[1] <https://bugs.astron.com/my_view_page.php>
 [2021-12-20 09:39 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #77784: mime_content_type result gets doubled for xlsx.
On GitHub:  https://github.com/php/php-src/pull/7800
Patch:      https://github.com/php/php-src/pull/7800.patch
 [2024-05-24 21:41 UTC] nielsdos@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: nielsdos
 [2024-05-24 21:41 UTC] nielsdos@php.net
I checked whether this bug still exists on the currently lowest-supported bugfix version, and it appears this is fixed. It must've been fixed between PHP 7.3 and PHP 8.2. Closing this now.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 06 11:01:27 2024 UTC