|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80887 MIME type is changed for archives created by ZipArchive
Submitted: 2021-03-19 00:45 UTC Modified: 2021-05-07 13:37 UTC
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: kolesnikov dot p at hotmail dot com Assigned:
Status: Open Package: Unknown/Other Function
PHP Version: 8.0.3 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-03-19 00:45 UTC] kolesnikov dot p at hotmail dot com
In PHP 7 zip archive created with ZipArchive has MIME type 'application/zip'.
In PHP 8 MIME type is 'application/octet-stream'

Test script:

$zip = new ZipArchive();
$zip->open('', ZipArchive::CREATE);
$zip->addFromString('test.txt', 'file content goes here');

$info = new finfo(FILEINFO_MIME_TYPE);
echo $info->file('') . PHP_EOL;

Expected result:

Actual result:
PHP7: application/zip
PHP8: application/octet-stream


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-19 00:49 UTC] kolesnikov dot p at hotmail dot com
Last line 
echo $info->file('') . PHP_EOL;
 [2021-03-23 14:15 UTC]
I wonder if there is really a difference between the created ZIP
archives (what might be caused by different libzip versions), or
whether there is an issue with finfo.
 [2021-04-16 18:06 UTC] maxsem dot wiki at gmail dot com
This appears to be a problem with zip file versions.

File created with command-line zip 3.0:
$ file Zip archive data, at least v2.0 to extract

File created with the above code on 3 weeks old PHP 8.1-dev:
$ file Zip archive data, at least v1.0 to extract

Then I checked what finfo thinks about these files:

$ php -a
Interactive shell

php > $info = new finfo(FILEINFO_MIME_TYPE); echo $info->file('') . PHP_EOL;
php > $info = new finfo(FILEINFO_MIME_TYPE); echo $info->file('') . PHP_EOL;

But then I rebuilt my PHP with newer changes that include with friends and it started producing application/zip in both cases. Does that resolve this bug? Does it make sense to backport?
 [2021-05-07 13:37 UTC]
-Package: Zip Related +Package: Unknown/Other Function
 [2021-05-07 13:37 UTC]
Ah, thanks for the analysis!  So this is not a zip issue, but
rather related to fileinfo.  Regarding backporting libmagick 5.40
to PHP 8.0: might be reasonable.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Dec 01 23:01:26 2023 UTC