Media: Avoid an infinite loop between `wp_getimagesize()` and `wp_get_image_mime()`.

As a result of the recent changes, both functions were calling each other if the `exif` PHP extension is not available.

The issue is now resolved by calling the `getimagesize()` PHP function directly, instead of the `wp_getimagesize()` wrapper.

Follow-up to [50146], [50810], [50814], [50815], [50818-50821].

See #35725.
Built from https://develop.svn.wordpress.org/trunk@50822


git-svn-id: http://core.svn.wordpress.org/trunk@50431 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2021-05-07 09:33:01 +00:00
parent c6028577a4
commit 5354201954
2 changed files with 14 additions and 3 deletions

View File

@ -3044,6 +3044,7 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
* This depends on exif_imagetype() or getimagesize() to determine real mime types. * This depends on exif_imagetype() or getimagesize() to determine real mime types.
* *
* @since 4.7.1 * @since 4.7.1
* @since 5.8.0 Added support for WebP images.
* *
* @param string $file Full path to the file. * @param string $file Full path to the file.
* @return string|false The actual mime type or false if the type cannot be determined. * @return string|false The actual mime type or false if the type cannot be determined.
@ -3059,7 +3060,17 @@ function wp_get_image_mime( $file ) {
$imagetype = exif_imagetype( $file ); $imagetype = exif_imagetype( $file );
$mime = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false; $mime = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false;
} elseif ( function_exists( 'getimagesize' ) ) { } elseif ( function_exists( 'getimagesize' ) ) {
$imagesize = wp_getimagesize( $file ); // Don't silence errors when in debug mode, unless running unit tests.
if ( defined( 'WP_DEBUG' ) && WP_DEBUG
&& ! defined( 'WP_RUN_CORE_TESTS' )
) {
// Not using wp_getimagesize() here to avoid an infinite loop.
$imagesize = getimagesize( $file );
} else {
// phpcs:ignore WordPress.PHP.NoSilencedErrors
$imagesize = @getimagesize( $file );
}
$mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false; $mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false;
} else { } else {
$mime = false; $mime = false;

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.8-alpha-50821'; $wp_version = '5.8-alpha-50822';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.