#28907 closed defect (bug) (fixed)
media_handle_upload calls wp_read_image_metadata on video files, causing errors and timeouts.
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.1 | Priority: | normal |
Severity: | normal | Version: | 3.8 |
Component: | Media | Keywords: | has-patch |
Focuses: | performance | Cc: |
Description
When uploading media files, if the mime type is anything other than audio/* then wp_read_image_metadata will be called on the file, even if the file is not an image.
This in turn calls getimagesize which will read the entire file trying to determine if it's (a) an image, and (b) it's dimensions. If we know the uploaded media has a mime type video/* (and probably others) then doing this is pointless. If it turns out your uploaded media is stored remotely, (e.g. on your CDN) then this results in failed uploads and timeouts as it takes a while to completely read large video files.
The most straightforward fix is to just check if the mime type is for a video and skip the call to wp_read_image_metadata, something like
Code highlighting:
} else if ( preg_match( '#^video#', $type ) === false ) {
if ( $image_meta = @wp_read_image_metadata( $file ) ) {
if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) )
$title = $image_meta['title'];
if ( trim( $image_meta['caption'] ) )
$content = $image_meta['caption'];
}
}
Attachments (1)
Change History (8)
#2
@
11 years ago
- Keywords has-patch added; needs-patch removed
I've added a patch implementing the suggestion by slangley.
Better would be IMHO to create a separate case for video which would look for the relevant information, though as there are lots of different places that information could be, that's beyond the scope of this bug.
#3
@
11 years ago
Thanks slangley or for filing this bug report and to SergeyBiryukov and jrf handling this, as I was the one that had the original issue (http://wordpress.org/support/topic/large-uploads-die-with-503-service-unavailable).
However, I wonder if just checking if 'not video' is enough? We use WordPress to host ZIP archives also (for interactives), which seems to be 'natively' supported as an 'archive' (e.g. with wp-includes/images/media/archive.png). Should ZIP archives also be be downloaded and have it's image dimensions evaluated?
Is it too dangerous just to check if the $type is some form of image?
Thanks again for all your help!
#5
@
11 years ago
- Owner set to wonderboymusic
- Resolution set to fixed
- Status changed from new to closed
In 29737:
Patch as suggested by submitter