Skip to content

Commit 1763d35

Browse files
Media: Fix sideload size validation for animated GIF video companion files.
Update the dimension validation introduced in [62619] so sideloading the `animated_video` and `animated_video_poster` companion sizes added in [62623] work as expected. Follow-up to [62619], [62623]. Props mukesh27. See #65549, #64798. git-svn-id: https://develop.svn.wordpress.org/trunk@62628 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6d62dc4 commit 1763d35

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,6 +2220,15 @@ private function validate_image_dimensions( int $width, int $height, string $ima
22202220
return true;
22212221
}
22222222

2223+
/*
2224+
* 'animated_video_poster' companion: a static poster image for the
2225+
* converted video. It is a real image (so it has positive dimensions)
2226+
* but is not a registered sub-size, so it has no dimension constraint.
2227+
*/
2228+
if ( 'animated_video_poster' === $image_size ) {
2229+
return true;
2230+
}
2231+
22232232
// Regular image sizes: validate against registered size constraints.
22242233
$registered_sizes = wp_get_registered_image_subsizes();
22252234

@@ -2367,12 +2376,19 @@ public function sideload_item( WP_REST_Request $request ) {
23672376
$image_size = $request['image_size'];
23682377

23692378
/*
2370-
* Validate raster sub-sizes before storing them. Source-format companion
2371-
* originals (e.g. a HEIC or JXL kept next to its JPEG derivative) are
2372-
* exempt: their dimensions are neither validated nor recorded, and the
2373-
* source format may not be readable by wp_getimagesize() at all.
2379+
* Validate raster sub-sizes before storing them. Two companion sizes
2380+
* are exempt because wp_getimagesize() may not be able to read the
2381+
* file at all: the 'animated_video' companion of an animated GIF is a
2382+
* video (MP4/WebM), and a source-format original (e.g. a HEIC or JXL
2383+
* kept next to its JPEG derivative) may be an unreadable format. Their
2384+
* dimensions are neither validated nor recorded. The
2385+
* 'animated_video_poster' companion is a real image, so it is still
2386+
* read and rejected if unreadable; validate_image_dimensions() skips
2387+
* only the registered-size constraint for it.
23742388
*/
2375-
if ( self::IMAGE_SIZE_SOURCE_ORIGINAL !== $image_size ) {
2389+
$skip_dimension_read = in_array( $image_size, array( self::IMAGE_SIZE_SOURCE_ORIGINAL, 'animated_video' ), true );
2390+
2391+
if ( ! $skip_dimension_read ) {
23762392
/*
23772393
* Read the dimensions up front. A file whose dimensions cannot be
23782394
* read is corrupted or an unsupported format and must be rejected

0 commit comments

Comments
 (0)