[wp-trac] [WordPress Trac] #64902: wp_save_image() fatal error when wp_save_image_file() returns WP_Error
WordPress Trac
noreply at wordpress.org
Tue May 26 11:49:20 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 | Resolution:
Keywords: has-patch needs-testing | Focuses:
-------------------------------------+------------------------------
Comment (by ekamran):
== Test Report ==
Patch tested: attachment:64902.patch
=== Environment ===
* Reported version: 6.9.4
* Tested version: 7.1-alpha-62161-src
* PHP: 8.3.31
* Environment: wordpress-develop local Docker environment
* Test method: WP-CLI automated reproduction using
`wp_save_image_editor_file`
* OS: macOS
=== Reproduction ===
I was able to confirm that the reported issue is still reproducible on
current trunk.
The test creates an image attachment from `tests/phpunit/data/images/test-
image.jpg`, sets up a scale operation for `wp_save_image()`, and uses the
existing `wp_save_image_editor_file` filter to force
`wp_save_image_file()` to return a `WP_Error`.
Clean trunk output:
{{{
attachment_id=10
source_size=50x50
request={"do":"scale","fwidth":25,"fheight":25,"target":"all"}
Fatal error: Uncaught Error: Cannot use object of type WP_Error as array
in /var/www/src/wp-admin/includes/image-edit.php:1054
}}}
This confirms that when `wp_save_image_file()` returns `WP_Error`,
`wp_save_image()` continues as if it received an array and then fatals
when reading `$saved_image['filesize']`.
=== Patch Result ===
After applying `64902.patch` locally and running the same automated
reproduction, the fatal error no longer occurs. `wp_save_image()` returns
a normal error response:
{{{
attachment_id=11
source_size=50x50
request={"do":"scale","fwidth":25,"fheight":25,"target":"all"}
result={
"error": "Forced save failure for #64902 retest."
}
}}}
=== Tests ===
I also ran the related PHPUnit tests with the patch applied:
{{{
npm run test:php -- --group ajax --filter Tests_Ajax_wpAjaxImageEditor
OK (4 tests, 9 assertions)
}}}
{{{
npm run test:php -- --filter Tests_Image_Functions
OK (113 tests, 211 assertions)
}}}
=== Notes ===
The patch handles the `WP_Error` return from `wp_save_image_file()` before
the code accesses `$saved_image['filesize']`, which prevents the fatal and
returns a normal error response instead.
A focused PHPUnit test using the `wp_save_image_editor_file` filter to
force a `WP_Error` return would be a useful follow-up for this patch.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64902#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list