REST API: Exempt animated GIF video companions from sideload dimension validation#12393
Conversation
…n 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.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Hi there! 👋 Thank you for your contribution to WordPress! 💖 It looks like this is your first pull request to No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making. More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook. Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook. If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook. The Developer Hub also documents the various coding standards that are followed:
Thank you, |
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.
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
Pull request overview
This pull request updates the REST API media sideload flow to accommodate animated GIF “video companion” uploads by exempting the animated_video companion (MP4/WebM) from image-dimension reading/validation, while still allowing the animated_video_poster companion (a real image) to be dimension-read and checked for positive dimensions but not constrained to a registered sub-size.
Changes:
- Skip
wp_getimagesize()and all dimension validation forimage_size=animated_videoinsideload_item(). - Exempt
animated_video_posterfrom the “must be a registered image sub-size” constraint invalidate_image_dimensions().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Committed at https://core.trac.wordpress.org/changeset/62628 |
Trac ticket: https://core.trac.wordpress.org/ticket/65549
What
Fixes the PHPUnit failure on trunk introduced by the combination of [62619] and [62623]:
Failing run: https://github.com/WordPress/wordpress-develop/actions/runs/28562019769/attempts/2
Why the failure only appeared on trunk
This is a semantic conflict between two individually green commits:
image_sizeother than_source_originalis now checked againstwp_get_registered_image_subsizes()and rejected withrest_upload_unknown_size(400) when not registered.animated_video/animated_video_postercompanion sizes. The PR branch last merged trunk at 19:11 UTC on July 1, before [62619] landed at 21:32 UTC, so its CI ran against a trunk without dimension validation and passed.Once both were on trunk, sideloading a companion hit the new validation:
animated_videois not a registered sub-size, so the request returns 400.Beyond the test, the real feature flow was broken too: the actual companion is an MP4/WebM video, and
wp_getimagesize()cannot read it, which would fail withrest_upload_invalid_imageeven before the unknown-size check.Fix
In
sideload_item(), skip thewp_getimagesize()read and all dimension checks for theanimated_videocompanion (like the existing_source_originalexemption), since a video is not image-readable. Theanimated_video_postercompanion is a real image, so it keeps the readability and positive-dimension checks;validate_image_dimensions()skips only the registered-size constraint for it.Testing
tests/phpunit/tests/rest-api/rest-attachments-controller.php --filter test_sideload_animated_video_companions_write_metadatapasses.restattachmentsgroup passes locally.Parity with Gutenberg
The exemption semantics match the Gutenberg polyfill in GB PR #79603 (
Gutenberg_REST_Attachments_Controller):animated_video(MP4/WebM) and_source_original: skip thewp_getimagesize()read and all dimension checks - the file may not be image-readable at all.animated_video_poster: still read viawp_getimagesize()and rejected if unreadable (it is a real image); only the registered-size constraint is skipped.Commit message