Skip to content

Media: guard attachment icon size lookup#11613

Open
dhrupo wants to merge 2 commits into
WordPress:trunkfrom
dhrupo:ticket-64742-guard-attachment-icon-size
Open

Media: guard attachment icon size lookup#11613
dhrupo wants to merge 2 commits into
WordPress:trunkfrom
dhrupo:ticket-64742-guard-attachment-icon-size

Conversation

@dhrupo

@dhrupo dhrupo commented Apr 21, 2026

Copy link
Copy Markdown

Summary

Add a regression test for the icon fallback path in wp_get_attachment_image_src() when wp_getimagesize() cannot read the icon file.

This is a test-only follow-up to [r62176], which fixed the underlying issue. That changeset guarded the icon fallback so that when wp_getimagesize() returns a falsey value (the icon file cannot be read), width and height are only read when an array is returned — preserving the existing false return behavior instead of surfacing an incorrect array access on PHP 8.5.

This PR does not change any source; it adds coverage to lock in that behavior.

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

Testing

Added a PHPUnit regression test that forces the mime type icon path to point at a missing icon file and verifies wp_get_attachment_image_src() returns false cleanly.

Verified in the configured local wordpress-develop environment with:

  • node ./tools/local-env/scripts/docker.js exec --user wp_php php ./vendor/bin/phpunit --filter test_wp_get_attachment_image_src_with_icon_when_icon_file_size_cannot_be_read tests/phpunit/tests/media.php
  • node ./tools/local-env/scripts/docker.js exec --user wp_php php ./vendor/bin/phpunit --filter 'test_wp_get_attachment_image_(url|src_with_icon_when_icon_file_size_cannot_be_read)' tests/phpunit/tests/media.php

@github-actions

github-actions Bot commented Apr 21, 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 dhrupo, westonruter, masteradhoc.

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

@dhrupo dhrupo force-pushed the ticket-64742-guard-attachment-icon-size branch from e220135 to 3496f8b Compare April 21, 2026 06:56
@github-actions

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.

Comment thread tests/phpunit/tests/media.php Outdated
Comment on lines +1749 to +1753
$filter = static function () {
return 'https://example.org/wp-includes/images/media/missing-icon.png';
};

add_filter( 'wp_mime_type_icon', $filter );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
$filter = static function () {
return 'https://example.org/wp-includes/images/media/missing-icon.png';
};
add_filter( 'wp_mime_type_icon', $filter );
add_filter(
'wp_mime_type_icon',
static function () {
return 'https://example.org/wp-includes/images/media/missing-icon.png';
}
);

Comment thread tests/phpunit/tests/media.php Outdated
Comment on lines +1756 to +1757

remove_filter( 'wp_mime_type_icon', $filter );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to remove filters manually. This is done automatically when a test runs.

Suggested change
remove_filter( 'wp_mime_type_icon', $filter );

Comment thread tests/phpunit/tests/media.php Outdated
/**
* @ticket 64742
*/
public function test_wp_get_attachment_image_src_with_icon_when_icon_file_size_cannot_be_read() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
public function test_wp_get_attachment_image_src_with_icon_when_icon_file_size_cannot_be_read() {
public function test_wp_get_attachment_image_src_with_icon_when_icon_file_size_cannot_be_read(): void {

@westonruter

Copy link
Copy Markdown
Member

Guard the icon fallback path in wp_get_attachment_image_src() when wp_getimagesize() cannot read the icon file.

This PR is only including a test, right? The PR description makes it sounds like it is attempting to fix something.

If so, please make it clear this is a follow-up to r62176.

@masteradhoc

Copy link
Copy Markdown

@dhrupo thanks for this PR. Would you have some time over the next days to take a look at this? We'd potentially want to include this in WP 7.0.1 and would need the feedback fixed to continue. Else feel free to let us know.

@dhrupo

dhrupo commented Jun 27, 2026

Copy link
Copy Markdown
Author

@masteradhoc thanks for the nudge — done, the review feedback is now addressed:

  • @westonruter's three inline suggestions are applied: added the : void return type, inlined the wp_mime_type_icon filter closure, and dropped the manual remove_filter() teardown (handled automatically between tests).
  • Updated the PR description to make clear this is a test-only follow-up to r62176 — the underlying fix already landed there; this PR only adds regression coverage.

Both tests pass locally:

OK (2 tests, 3 assertions)

Should be good to include in 7.0.1. Let me know if you'd like anything else adjusted.

@dhrupo dhrupo requested a review from westonruter June 27, 2026 03:45
Apply review suggestions: add void return type, inline the filter
closure, and drop the manual remove_filter() teardown.
@dhrupo dhrupo force-pushed the ticket-64742-guard-attachment-icon-size branch from c6a6970 to 47ce51e Compare June 27, 2026 03:46
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