From 5354201954e2dc7848cd29a2f6e27f4e594f285e Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 7 May 2021 09:33:01 +0000 Subject: [PATCH] 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 --- wp-includes/functions.php | 15 +++++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index d8e90d82c7..3c7e204db3 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -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. * * @since 4.7.1 + * @since 5.8.0 Added support for WebP images. * * @param string $file Full path to the file. * @return string|false The actual mime type or false if the type cannot be determined. @@ -3059,8 +3060,18 @@ function wp_get_image_mime( $file ) { $imagetype = exif_imagetype( $file ); $mime = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false; } elseif ( function_exists( 'getimagesize' ) ) { - $imagesize = wp_getimagesize( $file ); - $mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false; + // 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; } else { $mime = false; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 59e2c12cb2..f3b8906a82 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @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.