[wp-trac] [WordPress Trac] #54637: wp_read_image_metadata() sends `false` instead of `array` for `$iptc` and `$exif` parameters to `wp_read_image_metadata` filter

WordPress Trac noreply at wordpress.org
Thu Dec 16 19:21:07 UTC 2021


#54637: wp_read_image_metadata() sends `false` instead of `array` for `$iptc` and
`$exif` parameters to `wp_read_image_metadata` filter
---------------------------------+-----------------------------
 Reporter:  volodymyrkolesnykov  |      Owner:  (none)
     Type:  defect (bug)         |     Status:  new
 Priority:  normal               |  Milestone:  Awaiting Review
Component:  General              |    Version:  5.8.2
 Severity:  normal               |   Keywords:
  Focuses:                       |
---------------------------------+-----------------------------
 According to the documentation
 (https://developer.wordpress.org/reference/hooks/wp_read_image_metadata/),
 the `exif_read_metadata` filter expects its `$iptc` and `$exif` parameters
 to be arrays.

 However, under some circumstances `wp_read_image_metadata()` function
 passes `false` instead of arrays.

 This happens, for example, when `exif_read_data()` fails to parse
 metadata, in which case it returns `false` (see
 https://www.php.net/manual/en/function.exif-read-data.php).

 https://github.com/WordPress/WordPress/blob/5.8.2/wp-
 admin/includes/image.php#L808

 The shape of the returned value is never checked, WP just uses `empty()`
 function to see if specific keys are set (`empty()` will return false for
 scalars).

 Finally, that `false` is passed to the filter:
 https://github.com/WordPress/WordPress/blob/5.8.2/wp-
 admin/includes/image.php#L894

 The same story is with `iptcparse()`:
 https://github.com/WordPress/WordPress/blob/5.8.2/wp-
 admin/includes/image.php#L740,
 https://www.php.net/manual/en/function.iptcparse.php

 I see two possible ways to fix this:
 1. Ensure that `$iptc` and `$exif` are arrays — check the return value of
 the parsing functions, or
 2. Update the documentation/PHP doc blocks to mention that those
 parameters can be `false`.

 I can submit a patch for this issue, just not sure which of the solutions
 is preferred.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54637>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list