From 1afcc34ab3598db4166bb836843284a6455db06c Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Thu, 2 Jul 2026 08:19:40 -0700 Subject: [PATCH 1/2] REST API: Exempt animated GIF video companions from sideload dimension validation The dimension validation added in [62619] rejects any scalar image_size that is not present in wp_get_registered_image_subsizes(). The animated_video and animated_video_poster companion sizes added in [62623] are not registered sub-sizes, so sideloading them fails with rest_upload_unknown_size (400) and the PHPUnit job fails on trunk. The real MP4/WebM companion would also fail before that check because wp_getimagesize() cannot read video files. Exempt the companion sizes from raster dimension validation, matching the existing _source_original exemption: companion dimensions are neither validated nor recorded, and the file may not be readable by wp_getimagesize() at all. See #65549. --- .../class-wp-rest-attachments-controller.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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..9fe98669a6419 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 @@ -2367,12 +2367,16 @@ 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 + * Validate raster sub-sizes before storing them. Companion files are * exempt: their dimensions are neither validated nor recorded, and the - * source format may not be readable by wp_getimagesize() at all. + * file may not be readable by wp_getimagesize() at all. This applies to + * source-format originals (e.g. a HEIC or JXL kept next to its JPEG + * derivative) and to the converted-video companions of an animated GIF + * (the MP4/WebM and its static first-frame poster). */ - if ( self::IMAGE_SIZE_SOURCE_ORIGINAL !== $image_size ) { + $companion_sizes = array( self::IMAGE_SIZE_SOURCE_ORIGINAL, 'animated_video', 'animated_video_poster' ); + + if ( ! in_array( $image_size, $companion_sizes, true ) ) { /* * Read the dimensions up front. A file whose dimensions cannot be * read is corrupted or an unsupported format and must be rejected From ce6049bca187315d38fda4045ccfe67d48cc9772 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Thu, 2 Jul 2026 08:25:56 -0700 Subject: [PATCH 2/2] Keep validating the animated_video_poster companion as an image Align with the Gutenberg implementation (GB PR #79603): only the animated_video companion (a video) and the source-format original skip the wp_getimagesize() read, since those files may not be image-readable at all. The poster is a real image, so an unreadable file is still rejected; validate_image_dimensions() skips only the registered-size constraint for it. See #65549. --- .../class-wp-rest-attachments-controller.php | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) 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 9fe98669a6419..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,16 +2376,19 @@ public function sideload_item( WP_REST_Request $request ) { $image_size = $request['image_size']; /* - * Validate raster sub-sizes before storing them. Companion files are - * exempt: their dimensions are neither validated nor recorded, and the - * file may not be readable by wp_getimagesize() at all. This applies to - * source-format originals (e.g. a HEIC or JXL kept next to its JPEG - * derivative) and to the converted-video companions of an animated GIF - * (the MP4/WebM and its static first-frame poster). + * 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. */ - $companion_sizes = array( self::IMAGE_SIZE_SOURCE_ORIGINAL, 'animated_video', 'animated_video_poster' ); + $skip_dimension_read = in_array( $image_size, array( self::IMAGE_SIZE_SOURCE_ORIGINAL, 'animated_video' ), true ); - if ( ! in_array( $image_size, $companion_sizes, 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