close

Make WordPress Core

Opened 3 months ago

Closed 3 months ago

#64417 closed defect (bug) (duplicate)

Check to see height and width exist in wp_get_missing_image_subsizes

Reported by: spacedmonkey's profile spacedmonkey Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.0
Component: Media Keywords:
Focuses: Cc:

Description

In wp-admin/includes/image.php, the function wp_get_missing_image_subsizes() triggers "Undefined array key" warnings for width and height when processing image metadata that lacks dimension data but contains other keys.

The function attempts to retrieve dimensions using the following code:

$full_width  = (int) $image_meta['width'];
$full_height = (int) $image_meta['height'];

There is an initial check at the top of the function: if ( empty( $image_meta ) ). However, this check is insufficient because $image_meta can be a non-empty array that still lacks dimensions. This appears to be a regression related to #49412, which modified wp_generate_attachment_metadata to include a filesize key. Consequently, if metadata generation partially fails or if only the filesize is stored, $image_meta is not empty, causing the code to fall through to the dimension assignment and throw PHP warnings.

To fix this, the guard clause should be updated to explicitly check for the existence of the required dimension keys, rather than relying solely on empty().

Change History (1)

#1 Image @sabernhardt
3 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

#57813 is already tracking this issue.

Note: See TracTickets for help on using tickets.