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. git-svn-id: https://develop.svn.wordpress.org/trunk@49019 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
8856579610
commit
e020b1183d
@ -93,13 +93,20 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
|
||||
// Set artificially high because GD uses uncompressed images in memory.
|
||||
wp_raise_memory_limit( 'image' );
|
||||
|
||||
$this->image = @imagecreatefromstring( file_get_contents( $this->file ) );
|
||||
$file_contents = @file_get_contents( $this->file );
|
||||
|
||||
if ( ! $file_contents ) {
|
||||
return new WP_Error( 'error_loading_image', __( 'File doesn’t exist?' ), $this->file );
|
||||
}
|
||||
|
||||
$this->image = @imagecreatefromstring( $file_contents );
|
||||
|
||||
if ( ! is_gd_image( $this->image ) ) {
|
||||
return new WP_Error( 'invalid_image', __( 'File is not an image.' ), $this->file );
|
||||
}
|
||||
|
||||
$size = @getimagesize( $this->file );
|
||||
|
||||
if ( ! $size ) {
|
||||
return new WP_Error( 'invalid_image', __( 'Could not read image size.' ), $this->file );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user