Make WordPress Core


Ignore:
Timestamp:
09/20/2020 02:26:38 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Media: Return a WP_Error from WP_Image_Editor_GD::load() if file contents could not be retrieved.

This avoids an error on PHP 8 caused by calling imagecreatefromstring() on an empty result.

See #50913.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-image-editor-gd.php

    r48798 r49019  
    9494        wp_raise_memory_limit( 'image' );
    9595
    96         $this->image = @imagecreatefromstring( file_get_contents( $this->file ) );
     96        $file_contents = @file_get_contents( $this->file );
     97
     98        if ( ! $file_contents ) {
     99            return new WP_Error( 'error_loading_image', __( 'File doesn’t exist?' ), $this->file );
     100        }
     101
     102        $this->image = @imagecreatefromstring( $file_contents );
    97103
    98104        if ( ! is_gd_image( $this->image ) ) {
     
    101107
    102108        $size = @getimagesize( $this->file );
     109
    103110        if ( ! $size ) {
    104111            return new WP_Error( 'invalid_image', __( 'Could not read image size.' ), $this->file );
Note: See TracChangeset for help on using the changeset viewer.