Make WordPress Core

Opened 4 years ago

Last modified 2 years ago

#50384 new defect (bug)

@getimagesize bug for some images: Returns empty

Reported by: samwebdev's profile samwebdev Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.4.1
Component: Media Keywords: reporter-feedback
Focuses: Cc:

Description (last modified by SergeyBiryukov)


Stumbled upon a bug at @getimagesize, which causes image generation to fail.

To replicate:


The original file will be available in /uploads/ folder; it browse fine in browser. Metadata generation will fail via wp_generate_attachment_metadata, hence thumbnail generations will fail.

Further checking, wp_create_image_subsizes is called, where

	$imagesize = @getimagesize( $file );

will try to get the image size, which it returns empty.

if ( empty( $imagesize ) ) {

	   // File is not an image.
           return array();

will return empty array, hence wp_generate_attachment_metadata will save empty metadata, hence any file generation will be cancelled.

Manually setting imagesize where @getimagesize fails, can confirm metadata generates fine and all file regenarations work.

if ( empty( $imagesize ) ) {

		$imagesize[0] = 1024;
		$imagesize[1] = 1024;

// File is not an image.
//		return array();

@getimagesize fails for some files.



Change History (3)

#1 @SergeyBiryukov
4 years ago

  • Component changed from General to Media
  • Description modified (diff)

This ticket was mentioned in Slack in #core-media by antpb. View the logs.

2 years ago

#3 @antpb
2 years ago

  • Keywords reporter-feedback added

hi @samwebdev ! Thanks for this report. Looking at the function today I notice we are using wp_getimagesize which better accounts for edge cases like these. Is it possible for you to test this again using the latest WordPress to ensure this is still happening?

Here's a link to the latest version of the code:

Note: See TracTickets for help on using tickets.