From ebc3417c2d7f71f65181913138968aa57f945af0 Mon Sep 17 00:00:00 2001 From: Mike Schroder Date: Thu, 28 Apr 2022 10:58:48 +0000 Subject: [PATCH] Media: Ensure `wp_read_image_metadata` filter returns array for `$iptc` and `$exif`. Makes the behavior of the filter lines up with its documentation. Previously, both `$iptc` and `$exif` could return `false` when `exif_read_data()` or `iptcparse()` failed. Now, if those functions do not return an array, the results are explicitly set to `array()`. Props volodymyrkolesnykov, SergeyBiryukov, sabernhardt, sumitsingh, mikeschroder. Fixes #54637. git-svn-id: https://develop.svn.wordpress.org/trunk@53303 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/image.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/wp-admin/includes/image.php b/src/wp-admin/includes/image.php index 136f6dcdab..74d08bf634 100644 --- a/src/wp-admin/includes/image.php +++ b/src/wp-admin/includes/image.php @@ -776,6 +776,10 @@ function wp_read_image_metadata( $file ) { $iptc = @iptcparse( $info['APP13'] ); } + if ( ! is_array( $iptc ) ) { + $iptc = array(); + } + // Headline, "A brief synopsis of the caption". if ( ! empty( $iptc['2#105'][0] ) ) { $meta['title'] = trim( $iptc['2#105'][0] ); @@ -845,6 +849,10 @@ function wp_read_image_metadata( $file ) { $exif = @exif_read_data( $file ); } + if ( ! is_array( $exif ) ) { + $exif = array(); + } + if ( ! empty( $exif['ImageDescription'] ) ) { mbstring_binary_safe_encoding(); $description_length = strlen( $exif['ImageDescription'] );