php-src icon indicating copy to clipboard operation
php-src copied to clipboard

finfo detects TrueType fonts as application/octet-stream since libmagic 5.48

Open dhrupo opened this issue 1 month ago • 6 comments

Description

Since the bundled libmagic was upgraded to 5.48 (bbb345b363), finfo no longer recognizes TrueType fonts.

The following code:

<?php
$finfo = new finfo(FILEINFO_MIME_TYPE);
var_dump($finfo->file('OpenSans-Regular.ttf'));

Resulted in this output on PHP 8.6.0-dev (PHP-8.6 branch, libmagic 5.48):

string(24) "application/octet-stream"

But I expected this output instead (PHP 8.5.12, libmagic 5.46):

string(9) "font/sfnt"

This is an upstream regression from the FontKit rule added in file 5.48. It was fixed upstream in https://github.com/file/file/commit/ba72caa54b ("TrueType fonts lose their MIME type since the FontKit change"). Loading the upstream magic from master with libmagic 5.48 gives font/ttf for the same file. Upstream changed the TrueType MIME type from font/sfnt to font/ttf earlier, in https://github.com/file/file/commit/6481672a8e.

OTF, WOFF and WOFF2 are detected as before. The font I used is tests/phpunit/data/fonts/OpenSans-Regular.ttf from wordpress-develop. WordPress font uploads of TTF files fail on 8.6 because of this.

PHP Version

PHP 8.6.0-dev (cli) (built: Oct 24 2026 22:20:09) (NTS)

Operating System

macOS 26 (arm64)

dhrupo avatar Oct 30 '26 08:10 dhrupo

@LamentXU123 is this something we can fix before the next 8.6 RC to avoid a regression? And/or should we consider reverting the upgrade?

DanielEScherzer avatar Oct 30 '26 18:10 DanielEScherzer

@DanielEScherzer Hmm, seems like all we need to do is just to backport https://github.com/file/file/commit/ba72caa54b ?

LamentXU123 avatar Oct 30 '26 18:10 LamentXU123

4. @DanielEScherzer Hmm, seems like all we need to do is just to backport file/file@ba72caa54b ?

No idea if there are also other parts that need to be updated, figured you would know and wanted to draw your attention to this

DanielEScherzer avatar Oct 30 '26 18:10 DanielEScherzer

Okay I will check through the upstream repo to see if there are other regressions. I plan to do it before GA cuz I am really busy recently. Let's first fix this #25063

LamentXU123 avatar Oct 30 '26 19:10 LamentXU123

7. Okay I will check through the upstream repo to see if there are other regressions. I plan to do it before GA cuz I am really busy recently. Let's first fix this #25063

Note that this should be done before 8.6.0 is branched, which happens at the last RC, i.e. is expected on Tuesday, November 3rd. After that the 8.6 branch is for 8.6.1 and you would need one of the 8.6 release managers to cherry pick the fix to the release branch

DanielEScherzer avatar Oct 30 '26 19:10 DanielEScherzer

Thanks!

LamentXU123 avatar Nov 10 '26 08:11 LamentXU123