diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php index 37e0199756aca..a8951db439d1c 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php @@ -2220,6 +2220,15 @@ private function validate_image_dimensions( int $width, int $height, string $ima return true; } + /* + * 'animated_video_poster' companion: a static poster image for the + * converted video. It is a real image (so it has positive dimensions) + * but is not a registered sub-size, so it has no dimension constraint. + */ + if ( 'animated_video_poster' === $image_size ) { + return true; + } + // Regular image sizes: validate against registered size constraints. $registered_sizes = wp_get_registered_image_subsizes(); @@ -2367,12 +2376,19 @@ public function sideload_item( WP_REST_Request $request ) { $image_size = $request['image_size']; /* - * Validate raster sub-sizes before storing them. Source-format companion - * originals (e.g. a HEIC or JXL kept next to its JPEG derivative) are - * exempt: their dimensions are neither validated nor recorded, and the - * source format may not be readable by wp_getimagesize() at all. + * Validate raster sub-sizes before storing them. Two companion sizes + * are exempt because wp_getimagesize() may not be able to read the + * file at all: the 'animated_video' companion of an animated GIF is a + * video (MP4/WebM), and a source-format original (e.g. a HEIC or JXL + * kept next to its JPEG derivative) may be an unreadable format. Their + * dimensions are neither validated nor recorded. The + * 'animated_video_poster' companion is a real image, so it is still + * read and rejected if unreadable; validate_image_dimensions() skips + * only the registered-size constraint for it. */ - if ( self::IMAGE_SIZE_SOURCE_ORIGINAL !== $image_size ) { + $skip_dimension_read = in_array( $image_size, array( self::IMAGE_SIZE_SOURCE_ORIGINAL, 'animated_video' ), true ); + + if ( ! $skip_dimension_read ) { /* * Read the dimensions up front. A file whose dimensions cannot be * read is corrupted or an unsupported format and must be rejected