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.
Built from https://develop.svn.wordpress.org/trunk@53303


git-svn-id: http://core.svn.wordpress.org/trunk@52892 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Mike Schroder 2022-04-28 11:00:10 +00:00
parent c6dbcf8576
commit d9266d5bfd
2 changed files with 9 additions and 1 deletions

View File

@ -776,6 +776,10 @@ function wp_read_image_metadata( $file ) {
$iptc = @iptcparse( $info['APP13'] ); $iptc = @iptcparse( $info['APP13'] );
} }
if ( ! is_array( $iptc ) ) {
$iptc = array();
}
// Headline, "A brief synopsis of the caption". // Headline, "A brief synopsis of the caption".
if ( ! empty( $iptc['2#105'][0] ) ) { if ( ! empty( $iptc['2#105'][0] ) ) {
$meta['title'] = trim( $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 ); $exif = @exif_read_data( $file );
} }
if ( ! is_array( $exif ) ) {
$exif = array();
}
if ( ! empty( $exif['ImageDescription'] ) ) { if ( ! empty( $exif['ImageDescription'] ) ) {
mbstring_binary_safe_encoding(); mbstring_binary_safe_encoding();
$description_length = strlen( $exif['ImageDescription'] ); $description_length = strlen( $exif['ImageDescription'] );

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.0-beta3-53302'; $wp_version = '6.0-beta3-53303';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.