Make WordPress Core

Opened 10 months ago

Closed 4 days ago

#59573 closed defect (bug) (maybelater)

warning: trying to access array offset on value of type bool in wp-includes/media.php

Reported by: androidforlife's profile androidforlife Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.3.1
Component: Media Keywords: reporter-feedback
Focuses: Cc:

Description (last modified by sabernhardt)

function image_get_intermediate_size($post_id, $size = 'thumbnail')
{
    $imagedata = wp_get_attachment_metadata($post_id);

    // Checking whether $imagedata and $imagedata['sizes'] are real arrays.
    if (!is_array($imagedata) || empty($imagedata['sizes']) || !is_array($imagedata['sizes'])) {
        return false;
    }

    // Checking whether $size has a valid structure.
    if (!is_array($size) || count($size) < 2) {
        return false;
    }

    $data = [];

.....

Change History (6)

#1 @sabernhardt
9 months ago

  • Component changed from General to Media
  • Description modified (diff)
  • Summary changed from warning: trying to access array offset on value of type bool in wp-incloudes/media.php to warning: trying to access array offset on value of type bool in wp-includes/media.php

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


3 months ago

#3 @joedolson
3 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Where did that code come from? That's not code from any even moderately recent version of WordPress. If you're using an older version of WordPress, then you need to start by updating to the latest release.

#4 @sabernhardt
3 months ago

  • Keywords reporter-feedback added
  • Milestone set to Awaiting Review
  • Resolution invalid deleted
  • Status changed from closed to reopened

I expect the code in the description suggested a revision. The original comments were in German.

The $size condition is still flawed because that parameter can be a string (and is 'thumbnail' by default).

@androidforlife I should have asked for a PHP stack trace months ago to know what caused the error. Do you have a way to reproduce it now?

This ticket was mentioned in Slack in #core-media by joedolson. View the logs.


4 days ago

#6 @joedolson
4 days ago

  • Milestone Awaiting Review deleted
  • Resolution set to maybelater
  • Status changed from reopened to closed

The code may be a suggested revision, but it's not a good suggestion; the current code handles a string value better than that does, which would result in executing count() on a non-countable variable type.

Without any context on where this is coming from, I don't think there's any action we can take on this ticket.

If @androidforlife is able to provide a stack trace that tells us what to look at, we can re-open this, but I don't think it's productive to keep it open for now.

Note: See TracTickets for help on using tickets.