From 29451fb93c574438bc1bdbda3703dded5bd82b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Fri, 26 Aug 2022 11:54:27 -0400 Subject: [PATCH] add checks before using size data --- src/wp-includes/media.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 456cd7c988f9e..790c030ff77aa 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -774,24 +774,28 @@ function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { $imagedata['width'] = $imagedata['sizes']['full']['width']; } - foreach ( $imagedata['sizes'] as $_size => $data ) { + foreach ( $imagedata['sizes'] as $_size => $size_data ) { + if ( ! is_array( $size_data ) || ! isset( $size_data['width'] ) || ! isset( $size_data['height'] ) ) { + continue; + } + // If there's an exact match to an existing image size, short circuit. - if ( (int) $data['width'] === (int) $size[0] && (int) $data['height'] === (int) $size[1] ) { - $candidates[ $data['width'] * $data['height'] ] = $data; + if ( (int) $size_data['width'] === (int) $size[0] && (int) $size_data['height'] === (int) $size[1] ) { + $candidates[ $size_data['width'] * $size_data['height'] ] = $size_data; break; } // If it's not an exact match, consider larger sizes with the same aspect ratio. - if ( $data['width'] >= $size[0] && $data['height'] >= $size[1] ) { + if ( $size_data['width'] >= $size[0] && $size_data['height'] >= $size[1] ) { // If '0' is passed to either size, we test ratios against the original file. if ( 0 === $size[0] || 0 === $size[1] ) { - $same_ratio = wp_image_matches_ratio( $data['width'], $data['height'], $imagedata['width'], $imagedata['height'] ); + $same_ratio = wp_image_matches_ratio( $size_data['width'], $size_data['height'], $imagedata['width'], $imagedata['height'] ); } else { - $same_ratio = wp_image_matches_ratio( $data['width'], $data['height'], $size[0], $size[1] ); + $same_ratio = wp_image_matches_ratio( $size_data['width'], $size_data['height'], $size[0], $size[1] ); } if ( $same_ratio ) { - $candidates[ $data['width'] * $data['height'] ] = $data; + $candidates[ $size_data['width'] * $size_data['height'] ] = $size_data; } } }