Make WordPress Core


Ignore:
Timestamp:
03/30/2026 12:16:18 AM (2 months ago)
Author:
westonruter
Message:

Media: Guard against false return values from wp_get_attachment_image_src() and wp_getimagesize().

  • Add is_array() checks before accessing return values from wp_get_attachment_image_src() in get_oembed_response_data_rich(), wp_playlist_shortcode(), and wp_prepare_attachment_for_js().
  • Guard wp_getimagesize() calls within wp_get_attachment_image_src() itself.
  • Ensure wp_get_attachment_image_src() always returns the expected array{0: string, 1: int, 2: int, 3: bool} type or false by normalizing the filter result with explicit type casting and default values.
  • Add @phpstan-return annotations to both wp_get_attachment_image_src() and wp_getimagesize() for the specific array shapes.

Developed in https://github.com/WordPress/wordpress-develop/pull/11073

Props hbhalodia, westonruter, mukesh27, edent, ozgursar, roshniahuja14.
Fixes #64742.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/embed.php

    r61649 r62176  
    740740
    741741    if ( $thumbnail_id ) {
    742         list( $thumbnail_url, $thumbnail_width, $thumbnail_height ) = wp_get_attachment_image_src( $thumbnail_id, array( $width, 0 ) );
    743         $data['thumbnail_url']                                      = $thumbnail_url;
    744         $data['thumbnail_width']                                    = $thumbnail_width;
    745         $data['thumbnail_height']                                   = $thumbnail_height;
     742        $thumbnail_src = wp_get_attachment_image_src( $thumbnail_id, array( $width, 0 ) );
     743
     744        if ( is_array( $thumbnail_src ) ) {
     745            $data['thumbnail_url']    = $thumbnail_src[0];
     746            $data['thumbnail_width']  = $thumbnail_src[1];
     747            $data['thumbnail_height'] = $thumbnail_src[2];
     748        }
    746749    }
    747750
Note: See TracChangeset for help on using the changeset viewer.