Make WordPress Core

Opened 12 hours ago

Last modified 92 minutes ago

#64295 reopened defect (bug)

PHP 8.5: Incorrect array access in `wp_read_image_metadata`

Reported by: swissspidy's profile swissspidy Owned by: johnbillion's profile johnbillion
Milestone: 6.9 Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch php85 dev-feedback
Focuses: php-compatibility Cc:

Description

Parent ticket for all things PHP 8.5: #63061


In recent WP-CLI media tests I noticed a "Cannot use bool as array" error in wp_read_image_metadata in PHP 8.5.

That function uses wp_getimagesize without checking whether it returned false or an array.

Moving to milestone for consideration/visibility, but might be a candidate for 6.9.1.

Change History (13)

This ticket was mentioned in Slack in #core by wildworks. View the logs.


11 hours ago

#3 @wildworks
11 hours ago

  • Keywords needs-testing added

#4 @palak678
8 hours ago

I ran a quick test using WordPress 6.8.3 with PHP 8.4, and tried uploading a corrupted JPEG file to reproduce the behavior described in this ticket.

Here’s what I found:

getimagesize() throws warnings about corrupted JPEG data

exif_read_data() also reports corruption (invalid COM section, broken structure, etc.)

No fatal errors, but the metadata handling definitely breaks in the same way mentioned in the ticket

Log output for reference:

PHP Warning: getimagesize(): Corrupt JPEG data: 138 extraneous bytes before marker
PHP Notice: exif_read_data(): Image has corrupt COM section: wrong length information
PHP Warning: exif_read_data(): File structure corrupted
PHP Warning: exif_read_data(): Invalid JPEG file

So the issue is definitely reproducible on PHP 8.4.
The ticket still needs a patch to prevent array-access warnings when wp_getimagesize() returns false.

Happy to re-test once a patch is available!

#5 @swissspidy
5 hours ago

There is already a patch above... and the warning lccurs on PHP 8.5

#6 @adamsilverstein
4 hours ago

Fix looks good and makes sense.

In recent WP-CLI media tests I noticed a "Cannot use bool as array" error in wp_read_image_metadata in PHP 8.5.

Can we add a similar test to core that fails before your patch?

This ticket was mentioned in Slack in #core by welcher. View the logs.


2 hours ago

#8 @welcher
2 hours ago

  • Keywords commit added

This was discussed in the bug scrub today. This can be committed.

#9 @adamsilverstein
2 hours ago

In recent WP-CLI media tests I noticed a "Cannot use bool as array" error in wp_read_image_metadata in PHP 8.5.

@swissspidy which test failed?

#10 @johnbillion
2 hours ago

  • Owner set to johnbillion
  • Status changed from new to accepted

#11 @johnbillion
113 minutes ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 61291:

Media: Account for boolean false being returned by wp_getimagesize() when dealing with potentially invalid images in wp_read_image_metadata().

Prior to PHP 8.5 a boolean value was silently ignored when being passed to list(), but in PHP 8.5 and higher this now triggers a PHP warning. This change adds an appropriate guard condition.

Props swissspidy, adamsilverstein

Fixes #64295

#12 @johnbillion
112 minutes ago

  • Keywords dev-feedback added; needs-testing commit removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening to request backport of [61291] to the 6.9 branch.

#13 @swissspidy
92 minutes ago

@adamsilverstein You can see them here: https://github.com/wp-cli/media-command/actions/runs/19621010923/job/56181370548#step:10:158 - they're all about importing SVGs or PDFs, where no size information seems to be available.

Note: See TracTickets for help on using tickets.