Make WordPress Core

Changeset 50822


Ignore:
Timestamp:
05/07/2021 09:31:01 AM (3 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r50814 r50822  
    30453045 *
    30463046 * @since 4.7.1
     3047 * @since 5.8.0 Added support for WebP images.
    30473048 *
    30483049 * @param string $file Full path to the file.
     
    30603061            $mime      = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false;
    30613062        } elseif ( function_exists( 'getimagesize' ) ) {
    3062             $imagesize = wp_getimagesize( $file );
    3063             $mime      = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false;
     3063            // Don't silence errors when in debug mode, unless running unit tests.
     3064            if ( defined( 'WP_DEBUG' ) && WP_DEBUG
     3065                && ! defined( 'WP_RUN_CORE_TESTS' )
     3066            ) {
     3067                // Not using wp_getimagesize() here to avoid an infinite loop.
     3068                $imagesize = getimagesize( $file );
     3069            } else {
     3070                // phpcs:ignore WordPress.PHP.NoSilencedErrors
     3071                $imagesize = @getimagesize( $file );
     3072            }
     3073
     3074            $mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false;
    30643075        } else {
    30653076            $mime = false;
Note: See TracChangeset for help on using the changeset viewer.