Make WordPress Core

Opened 14 months ago

Last modified 6 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 14 months ago.
patch to wp-admin/includes/image.php

Download all attachments as: .zip

Change History (3)

@donbowman
14 months ago

patch to wp-admin/includes/image.php

#1 @Soean
13 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.

#2 @donbowman
6 months ago

This is another spot with the same issue, assuming width/height exist on svg. This is on 6.3.2

--- /app/wp-includes/media.php.orig	2023-10-28 15:19:04.671902110 +0000
+++ /app/wp-includes/media.php	2023-10-28 15:19:35.784547473 +0000
@@ -1642,6 +1642,8 @@
 	// Is it a full size image?
 	if (
 		isset( $image_meta['file'] ) &&
+		array_key_exists('width', $image_meta['file'] &&
+		array_key_exists('height', $image_meta['file'] &&
 		str_contains( $image_src, wp_basename( $image_meta['file'] ) )
 	) {
 		$dimensions = array(
Last edited 6 months ago by donbowman (previous) (diff)
Note: See TracTickets for help on using tickets.