Commit bf7b54a1ad for wordpress.org
commit bf7b54a1adc9de69f0627c7c49be88ef39fc1a16
Author: desrosj <desrosj@git.wordpress.org>
Date: Fri Nov 6 19:54:03 2026 +0000
Upload: Accept both valid MIME types reported for TrueType fonts.
The MIME type reported by libmagic for TrueType font files (`.ttf`) changed in version 5.47 from the abstract `font/sfnt` type to `font/ttf`, which `font/sfnt` is conceptually derived from.
The version of libmagic bundled by default in PHP 8.6 will include this change. However, PHP builds that use the system libmagic can report either type, regardless of the PHP version being used. Because `WP_Font_Utils::get_allowed_font_mime_types()` currently only expects and allows `font/sfnt`, uploading `.ttf` files to the Font Library will fail with a `rest_font_upload_invalid_file_type` error.
This adds TrueType fonts to the list of known alternate MIME types for `.ttf` files, allowing both `font/ttf` and `font/sfnt` to be considered valid and accepted. Files of other formats with a `.ttf` extension are still rejected. `WP_Font_Utils::get_allowed_font_mime_types()` will also now return `font/ttf` for TrueType fonts regardless of PHP or libmagic version.
While this ensures that both possible MIME types are considered valid, there is still a separate regression in PHP 8.6 that causes TrueType fonts to be detected as `application/octet-stream` instead of `font/ttf`. The issue has been addressed in libmagic, but the fix not been merged into the 8.6 release. Because this is a known upstream regression being tracked, the 2 relevant test methods will skip `.ttf` file-related tests when `application/octet-stream` is returned as the type for a `.ttf` file.
Follow-up to [57539].
Props dhrupo, desrosj.
Fixes #66419.
Built from https://develop.svn.wordpress.org/trunk@65319
git-svn-id: http://core.svn.wordpress.org/trunk@64459 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/fonts/class-wp-font-utils.php b/wp-includes/fonts/class-wp-font-utils.php
index ee175f66aa..57385ff808 100644
--- a/wp-includes/fonts/class-wp-font-utils.php
+++ b/wp-includes/fonts/class-wp-font-utils.php
@@ -236,11 +236,16 @@ class WP_Font_Utils {
/**
* Returns the expected mime-type values for font files, depending on PHP version.
*
- * This is needed because font mime types vary by PHP version, so checking the PHP version
- * is necessary until a list of valid mime-types for each file extension can be provided to
- * the 'upload_mimes' filter.
+ * This is needed because the mime types detected for WOFF and WOFF2 files vary by PHP version,
+ * so checking the PHP version is necessary until a list of valid mime-types for each file
+ * extension can be provided to the 'upload_mimes' filter.
+ *
+ * TrueType fonts can be detected as either font/ttf or font/sfnt depending on the libmagic
+ * version, and both are accepted by wp_check_filetype_and_ext(). The canonical font/ttf
+ * is returned for them on all PHP versions.
*
* @since 6.5.0
+ * @since 7.2.0 TrueType fonts now use the font/ttf mime type on all PHP versions.
*
* @access private
*
@@ -249,7 +254,7 @@ class WP_Font_Utils {
public static function get_allowed_font_mime_types() {
return array(
'otf' => 'application/vnd.ms-opentype',
- 'ttf' => 'font/sfnt',
+ 'ttf' => 'font/ttf',
'woff' => PHP_VERSION_ID >= 80112 ? 'font/woff' : 'application/font-woff',
'woff2' => PHP_VERSION_ID >= 80112 ? 'font/woff2' : 'application/font-woff2',
);
diff --git a/wp-includes/functions.php b/wp-includes/functions.php
index eac938b2c4..f31c53aa7d 100644
--- a/wp-includes/functions.php
+++ b/wp-includes/functions.php
@@ -3357,6 +3357,19 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
$type = false;
$ext = false;
}
+ } elseif ( in_array( $real_mime, array( 'font/ttf', 'font/sfnt' ), true ) ) {
+ /*
+ * libmagic 5.47 changed the type reported for TrueType fonts from font/sfnt to the
+ * canonical font/ttf. PHP 8.6 bundles a libmagic version with this change, but PHP
+ * builds that use the system libmagic can report either type, so both are accepted
+ * for TrueType fonts.
+ *
+ * @link https://github.com/file/file/commit/6481672a8eb64c2758bf6429d9a76ee5a22174e9
+ */
+ if ( ! in_array( $type, array( 'font/ttf', 'font/sfnt' ), true ) ) {
+ $type = false;
+ $ext = false;
+ }
} else {
if ( $type !== $real_mime ) {
/*
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 5e0274f309..d2f04585cf 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-beta4-65318';
+$wp_version = '7.2-beta4-65319';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.