Make WordPress Core

Opened 7 months ago

Last modified 7 months ago

#57813 new defect (bug)

wp_get_missing_image_subsizes() can give error if image_meta exists, but not height/width

Reported by: donbowman's profile donbowman Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.1.1
Component: Media Keywords: has-patch
Focuses: Cc:

Description

I have an SVG file attached as image. The function throws an error:

        if ( ! empty( $imagesize ) ) {
                $full_width  = $imagesize[0];
                $full_height = $imagesize[1];
        } else {
                $full_width  = (int) $image_meta['width'];
                $full_height = (int) $image_meta['height'];
        }

on the else case. The below patch will resolve.
This is with 6.1.1

--- /app/wp-admin/includes/image.php.orig	2023-02-26 21:42:57.687046116 +0000
+++ /app/wp-admin/includes/image.php	2023-02-26 21:40:41.349180739 +0000
@@ -89,11 +89,11 @@

 	$registered_sizes = wp_get_registered_image_subsizes();
 	$image_meta       = wp_get_attachment_metadata( $attachment_id );

 	// Meta error?
-	if ( empty( $image_meta ) ) {
+	if ( empty( $image_meta ) || !array_key_exists('width', $image_meta) || !array_key_exists('height', $image_meta) ) {
 		return $registered_sizes;
 	}

 	// Use the originally uploaded image dimensions as full_width and full_height.
 	if ( ! empty( $image_meta['original_image'] ) ) {

Attachments (1)

img.patch (634 bytes) - added by donbowman 7 months ago.
patch to wp-admin/includes/image.php

Download all attachments as: .zip

Change History (2)

@donbowman
7 months ago

patch to wp-admin/includes/image.php

#1 @Soean
7 months ago

I can reproduce the error with and SVG file in WP 6.2 Beta 5 with the new Media inserter in the block editor.

Note: See TracTickets for help on using tickets.