Skip to content

REST API: Exempt animated GIF video companions from sideload dimension validation#12393

Closed
adamsilverstein wants to merge 2 commits into
WordPress:trunkfrom
adamsilverstein:fix/sideload-animated-video-companion-validation
Closed

REST API: Exempt animated GIF video companions from sideload dimension validation#12393
adamsilverstein wants to merge 2 commits into
WordPress:trunkfrom
adamsilverstein:fix/sideload-animated-video-companion-validation

Conversation

@adamsilverstein

@adamsilverstein adamsilverstein commented Jul 2, 2026

Copy link
Copy Markdown
Member

Trac ticket: https://core.trac.wordpress.org/ticket/65549

What

Fixes the PHPUnit failure on trunk introduced by the combination of [62619] and [62623]:

1) WP_Test_REST_Attachments_Controller::test_sideload_animated_video_companions_write_metadata
Sideloading animated_video should succeed.
Failed asserting that 400 is identical to 200.

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:

  • [62619] (#64798) added dimension validation to the sideload endpoint: every scalar image_size other than _source_original is now checked against wp_get_registered_image_subsizes() and rejected with rest_upload_unknown_size (400) when not registered.
  • [62623] (#65549, PR Media: Add animated GIF to video sideload sizes and companion-file cleanup (backport GB #78410) #12005) added the animated_video / animated_video_poster companion 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_video is 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 with rest_upload_invalid_image even before the unknown-size check.

Fix

In sideload_item(), skip the wp_getimagesize() read and all dimension checks for the animated_video companion (like the existing _source_original exemption), since a video is not image-readable. The animated_video_poster companion 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_metadata passes.
  • The full restattachments group 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 the wp_getimagesize() read and all dimension checks - the file may not be image-readable at all.
  • animated_video_poster: still read via wp_getimagesize() and rejected if unreadable (it is a real image); only the registered-size constraint is skipped.

Commit message

Media: Fix sideload validation for animated GIF video companions.

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.

…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.
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props adamsilverstein.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

Hi there! 👋

Thank you for your contribution to WordPress! 💖

It looks like this is your first pull request to wordpress-develop. Here are a few things to be aware of that may help you out!

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,
The WordPress Project

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.
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 for image_size=animated_video in sideload_item().
  • Exempt animated_video_poster from the “must be a registered image sub-size” constraint in validate_image_dimensions().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mukeshpanchal27

Copy link
Copy Markdown
Member

Committed at https://core.trac.wordpress.org/changeset/62628

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants