Make WordPress Core


Ignore:
Timestamp:
02/02/2021 04:51:17 PM (3 years ago)
Author:
antpb
Message:

Media: Avoid suppressing errors when using getimagesize().

Previously, all logic utilizing getimagesize() was supressing errors making it difficult to debug usage of the function.

A new wp_getimagesize() function has been added to allow the errors to no longer be suppressed when WP_DEBUG is enabled.

Props Howdy_McGee, SergeyBiryukov, mukesh27, davidbaumwald, noisysocks, hellofromTonya.
Fixes #49889.

File:
1 edited

Legend:

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

    r49936 r50146  
    9494    if ( ! empty( $image_meta['original_image'] ) ) {
    9595        $image_file = wp_get_original_image_path( $attachment_id );
    96         $imagesize  = @getimagesize( $image_file );
     96        $imagesize  = wp_getimagesize( $image_file );
    9797    }
    9898
     
    225225 */
    226226function wp_create_image_subsizes( $file, $attachment_id ) {
    227     $imagesize = @getimagesize( $file );
     227    $imagesize = wp_getimagesize( $file );
    228228
    229229    if ( empty( $imagesize ) ) {
     
    688688    }
    689689
    690     list( , , $image_type ) = @getimagesize( $file );
     690    list( , , $image_type ) = wp_getimagesize( $file );
    691691
    692692    /*
     
    717717     */
    718718    if ( is_callable( 'iptcparse' ) ) {
    719         @getimagesize( $file, $info );
     719        wp_getimagesize( $file, $info );
    720720
    721721        if ( ! empty( $info['APP13'] ) ) {
    722             $iptc = @iptcparse( $info['APP13'] );
     722            if (
     723                // Skip when running unit tests.
     724                ! defined( 'DIR_TESTDATA' )
     725                &&
     726                // Process without silencing errors when in debug mode.
     727                defined( 'WP_DEBUG' ) && WP_DEBUG
     728            ) {
     729                $iptc = iptcparse( $info['APP13'] );
     730            } else {
     731                // phpcs:ignore WordPress.PHP.NoSilencedErrors -- Silencing notice and warning is intentional. See https://core.trac.wordpress.org/ticket/42480
     732                $iptc = @iptcparse( $info['APP13'] );
     733            }
    723734
    724735            // Headline, "A brief synopsis of the caption".
     
    780791
    781792    if ( is_callable( 'exif_read_data' ) && in_array( $image_type, $exif_image_types, true ) ) {
    782         $exif = @exif_read_data( $file );
     793        if (
     794            // Skip when running unit tests.
     795            ! defined( 'DIR_TESTDATA' )
     796            &&
     797            // Process without silencing errors when in debug mode.
     798            defined( 'WP_DEBUG' ) && WP_DEBUG
     799        ) {
     800            $exif = exif_read_data( $file );
     801        } else {
     802            // phpcs:ignore WordPress.PHP.NoSilencedErrors -- Silencing notice and warning is intentional. See https://core.trac.wordpress.org/ticket/42480
     803            $exif = @exif_read_data( $file );
     804        }
    783805
    784806        if ( ! empty( $exif['ImageDescription'] ) ) {
     
    878900 */
    879901function file_is_valid_image( $path ) {
    880     $size = @getimagesize( $path );
     902    $size = wp_getimagesize( $path );
    881903    return ! empty( $size );
    882904}
     
    893915    $displayable_image_types = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_ICO );
    894916
    895     $info = @getimagesize( $path );
     917    $info = wp_getimagesize( $path );
    896918    if ( empty( $info ) ) {
    897919        $result = false;
Note: See TracChangeset for help on using the changeset viewer.