[go: up one dir, main page]

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

fileinfo returns text/xml for some svg files #11891

Closed
ostrolucky opened this issue Aug 6, 2023 · 8 comments
Closed

fileinfo returns text/xml for some svg files #11891

ostrolucky opened this issue Aug 6, 2023 · 8 comments

Comments

@ostrolucky
Copy link

Description

The following code:

<?php
echo (new \finfo(\FILEINFO_MIME_TYPE))->file('svgfile.svg');

Resulted in this output:

text/xml

But I expected this output instead:

image/svg+xml

Here are example files:
logo_beta
Logo_SMC

I've reported same bug for file command line utility and they fixed it quickly: https://bugs.astron.com/view.php?id=470 (but I don't know how does the fix look like, I failed finding source code for their HEAD version)

PHP Version

8.2.8

Operating System

MacOS, Ubuntu

@usarise
Copy link
Contributor
usarise commented Aug 6, 2023

All because of unicode format, any SVG in UTF-16 encoding is recognized as text/xml,
encoding="UTF-16" from example does not matter, it is the initial bytes of the file that are important.

And it doesn't look like it's a mistake

@Girgias
Copy link
Member
Girgias commented Aug 7, 2023

This seems to be fixed upstream

@Girgias Girgias closed this as not planned Won't fix, can't repro, duplicate, stale Aug 7, 2023
@ostrolucky
Copy link
Author

Which upstream? Does this mean this will be fixed in next PHP patch version?

@usarise
Copy link
Contributor
usarise commented Aug 8, 2023

@ostrolucky fixed upstream file/file@006b37f
No, PHP bundled magic database not yet updated.
Backport fix probably won't happen...

@usarise
Copy link
Contributor
usarise commented Aug 8, 2023

@ostrolucky You can use a patched file https://raw.githubusercontent.com/file/file/master/magic/Magdir/sgml

<?php
echo (new \finfo(\FILEINFO_MIME_TYPE, 'sgml'))->file('svgfile.svg');

@Girgias
Copy link
Member
Girgias commented Aug 8, 2023

@ostrolucky fixed upstream file/file@006b37f No, PHP bundled magic database not yet updated. Backport fix probably won't happen...

I don't know what @weltling's process is for updating the bundled library, but he seems to apply fixes onto stable releases, but the last syncing was done on the 1st of July.

Part of the process is described here: #11298 (comment) so if someone wants to make a PR.

@usarise
Copy link
Contributor
usarise commented Aug 11, 2023

Made a backport, not sure if I sent it correctly pull request..

weltling added a commit that referenced this issue Sep 30, 2023
[ci skip]

Signed-off-by: Anatol Belski <ab@php.net>
weltling added a commit that referenced this issue Sep 30, 2023
* PHP-8.1:
  NEWS: Added note about #11891
weltling added a commit that referenced this issue Sep 30, 2023
[ci skip]

Signed-off-by: Anatol Belski <ab@php.net>
weltling added a commit that referenced this issue Sep 30, 2023
* PHP-8.2:
  NEWS: Added note about #11891
  NEWS: Added note about #11891
weltling added a commit that referenced this issue Sep 30, 2023
[ci skip]

Signed-off-by: Anatol Belski <ab@php.net>
weltling added a commit that referenced this issue Sep 30, 2023
* PHP-8.3:
  NEWS: Add note about #11891
  NEWS: Added note about #11891
  NEWS: Added note about #11891
@weltling
Copy link
Contributor

Fixed via #11943.

Thanks

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

5 participants