Opened 17 hours ago
Last modified 5 hours ago
#65748 reviewing defect (bug)
Image editor: fatal error when attachment metadata has no `sizes` array
| Reported by: | josephscott | Owned by: | westonruter |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.1 |
| Component: | Media | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
I noticed some fatal errors in wp_save_image() on a site recently.
Uncaught TypeError: array_merge(): Argument #1 must be of type array, null given
That came from this line - https://github.com/WordPress/wordpress-develop/blame/trunk/src/wp-admin/includes/image-edit.php#L1132
$meta['sizes'] = array_merge( $meta['sizes'], $img->multi_resize( $_sizes ) );
While I suspect this is something wrong or a mistake with the image, after looking at the code WordPress needs to make sure that $meta['sizes'] exists before using it.
There is a similar issue with wp_restore_image().
Change History (3)
This ticket was mentioned in PR #12744 on WordPress/wordpress-develop by @josephscott.
16 hours ago
#1
- Keywords has-patch has-unit-tests added
nazmulasif commented on PR #12744:
5 hours ago
#3
## Test Report
Patch tested: https://github.com/WordPress/wordpress-develop/pull/12744
### Environment
- WordPress: 7.1-beta3-20260728.201755
- Subdirectory: No
- PHP: 7.4.33
- Server: PHP.wasm
- Database: WP_SQLite_Driver (Server: 8.0.38 / Client: 3.51.0)
- Browser: Chrome 150.0.0.0
- OS: macOS
- Theme: Twenty Twenty-Five 1.5
- MU Plugins: None activated
- Plugins:
- Test Reports 1.3.0
### Steps taken
- Launched the WordPress Playground instance built from PR #12744.
- Navigated to Media → Library and uploaded a test image.
- Clicked Edit Image to open the core image editor interface.
- Performed Crop and Scale operations, then saved the modifications.
- Clicked Restore Original Image to revert the image back to its original state.
- Verified that no PHP fatal errors or warnings occurred during the process.
- ✅ Patch is solving the problem
### Expected result
- Image saving, cropping, scaling, and restoring operations should execute successfully without throwing PHP type errors or fatal errors when processing attachment metadata.
### Additional Notes
- Tested via WordPress Playground instance. Crop, scale, and restore functionalities work as expected without any errors.
### Screenshots/Screencast with results
- Screenshot/Screencast before: N/A
- Screenshot/Screencast after: N/A
### Support Content
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
https://core.trac.wordpress.org/ticket/65748
AI assistance: Yes
Tool(s): Claude
Model(s): Opus 5
Used for: Writing the tests