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
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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
44 + 4 = ?
Subscribe to this entry?

 
 [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-2021 The PHP Group
All rights reserved.
Last updated: Fri Sep 24 16:03:41 2021 UTC