[wp-trac] [WordPress Trac] #64902: wp_save_image() fatal error when wp_save_image_file() returns WP_Error
WordPress Trac
noreply at wordpress.org
Thu Mar 19 14:52:41 UTC 2026
#64902: wp_save_image() fatal error when wp_save_image_file() returns WP_Error
--------------------------+-----------------------------
Reporter: notglossy | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: 6.9.4
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
[https://developer.wordpress.org/reference/functions/wp_save_image_file/
wp_save_image_file()] has a return type of {{{array|WP_Error|bool}}}.
[https://developer.wordpress.org/reference/functions/wp_save_image/
wp_save_image()] checks the return value of {{{wp_save_image_file()}}}
with {{{ if ( ! $saved_image ) }}} [https://github.com/WordPress
/wordpress-develop/blob/074792ef21d9160a8fabdda215f8bf48f7a91d43/src/wp-
admin/includes/image-edit.php#L1020 (line1020)], but {{{WP_Error}}} is
truthy, so it passes through.
[https://github.com/WordPress/wordpress-
develop/blob/074792ef21d9160a8fabdda215f8bf48f7a91d43/src/wp-
admin/includes/image-edit.php#L1054 Line 1054] then accesses
{{{$saved_image['filesize']}}} which fatals with {{{"Cannot use object of
type WP_Error as array"}}}.
This is reproducible when any image editor's {{{save()}}} returns
{{{WP_Error}}} (e.g., unsupported format, disk full, encoder failure)
Affects all editors ([https://github.com/WordPress/wordpress-
develop/blob/074792ef21d9160a8fabdda215f8bf48f7a91d43/src/wp-includes
/class-wp-image-editor-gd.php#L483 GD], [https://github.com/WordPress
/wordpress-develop/blob/074792ef21d9160a8fabdda215f8bf48f7a91d43/src/wp-
includes/class-wp-image-editor-imagick.php#L855 Imagick], custom) since
{{{save()}}} is documented as {{{@return array|WP_Error}}}
This bug was discovered when building a plugin which extends
{{{WP_Image_Editor}}} to take advantage of a different graphics library.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64902>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list