php.net |  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
Votes:2
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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kolesnikov dot p at hotmail dot com
New email:
PHP Version: OS:

 

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

Test script:
---------------
<?php

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

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

Expected result:
----------------
application/zip

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-19 00:49 UTC] kolesnikov dot p at hotmail dot com
Last line 
echo $info->file('test.zip') . PHP_EOL;
 [2021-03-23 14:15 UTC] cmb@php.net
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 test.zip
test.zip: Zip archive data, at least v2.0 to extract

File created with the above code on 3 weeks old PHP 8.1-dev:
$ file test1.zip
test1.zip: 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('test1.zip') . PHP_EOL;
application/octet-stream
php > $info = new finfo(FILEINFO_MIME_TYPE); echo $info->file('test.zip') . PHP_EOL;
application/zip

But then I rebuilt my PHP with newer changes that include https://github.com/php/php-src/commit/3b9173dc8f3bda99e87003f6b6b2a16fa25c1b72#diff-4371103b525bd66a8f9765a700a60276ee5a5e26115b9aeb190e6657c457862e 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] cmb@php.net
-Package: Zip Related +Package: Unknown/Other Function
 [2021-05-07 13:37 UTC] cmb@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 18:01:28 2024 UTC