From 2884b7b1b7a76eb591d7a8cdca2ad90e72fd43cd Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 20 Sep 2020 14:28:05 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@49019 git-svn-id: http://core.svn.wordpress.org/trunk@48781 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-image-editor-gd.php | 9 ++++++++- wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/wp-includes/class-wp-image-editor-gd.php b/wp-includes/class-wp-image-editor-gd.php index 4fa1fe24fa..abf03c869b 100644 --- a/wp-includes/class-wp-image-editor-gd.php +++ b/wp-includes/class-wp-image-editor-gd.php @@ -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 ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index e3d6449671..b64a1ba947 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.6-alpha-49018'; +$wp_version = '5.6-alpha-49019'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.