Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finfo returns wrong mime type for (.tar).xz files #11298

Closed
nilllzz opened this issue May 22, 2023 · 2 comments
Closed

finfo returns wrong mime type for (.tar).xz files #11298

nilllzz opened this issue May 22, 2023 · 2 comments

Comments

@nilllzz
Copy link

nilllzz commented May 22, 2023

Description

Running a mime type detection on .xz archive files returns an incorrect mime type.

This code:

$path = "[Path to .xz file]";
$finfo = new \finfo(FILEINFO_MIME_TYPE);
$mimeData = $finfo->file($path);
echo $mimeData;

Resulted in this output:

"application/octet-stream"

But I expected this output instead:

"application/x-xz; charset=binary"

This is apparently an issue with libmagic version 5.40 and was fixed in 5.41 (ref https://bugs.astron.com/view.php?id=257).
The specific fix to the magic file can be found here: file/file@9b0459a

I suggest a similar fix to GH-8805 that was done in 34fa65a, since the issue seems very similar.

PHP Version

PHP 8.2.3

Operating System

No response

@iluuu1994
Copy link
Member

@nilllzz Thank you for the detailed report!

@weltling Hi! Is this process documented somewhere? I see ext/fileinfo/data_file.c is generated by ext/fileinfo/create_data_file.php, but I'm not sure how the patch files are related, and where/when to apply them. Also, my local magic.mgc file produces massive changes to data_file.c, some I'm guessing there's some canonical one to use?

weltling added a commit that referenced this issue Jul 1, 2023
Upstream: file/file@9b0459a

Fixes: #11298

Signed-off-by: Anatol Belski <ab@php.net>
@weltling
Copy link
Contributor

weltling commented Jul 1, 2023

@iluuu1994 no much docs on that and in many cases things have to be done manually. We carry magicdata.patch which has to be applied to libmagic before creating the magic db binary. That one is then used for embedding in the PHP sources.

Thanks

weltling added a commit that referenced this issue Jul 1, 2023
Ref: #11298

Signed-off-by: Anatol Belski <ab@php.net>
weltling added a commit that referenced this issue Jul 1, 2023
[ci skip]

Signed-off-by: Anatol Belski <ab@php.net>
weltling added a commit that referenced this issue Jul 1, 2023
* PHP-8.1:
  NEWS: Add note for #11298
weltling added a commit that referenced this issue Jul 1, 2023
[ci skip]

Signed-off-by: Anatol Belski <ab@php.net>
weltling added a commit that referenced this issue Jul 1, 2023
* PHP-8.2:
  NEWS: Add note for #11298
  NEWS: Add note for #11298
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants