\XF\Entity\Thread::getCoverUrl() may cause undefined array key

Kirby

Well-known member
Affected version
2.3.4
XF\Entity\CoverImageTrait::getCoverImageInternal()

PHP:
/** @var Attachment $attachment */
if ($embeddedAttachments[$attachment->attachment_id])
{
    continue;
}

This calls \XF\Mvc\AbstractCollection::offsetGet()
PHP:
public function offsetGet($key): ?Entity
{
    return $this->entities[$key];
}

As can be seen, this directly accesses the internal array without checking if the key exists, so if it does not exist this generates a warning Undefined array key ...

It's a bit tricky to actually see this warning as \XF\Template\Templater::handleTemplateError() hides it so this needs to be called by code outside of templater context.
 
Back
Top Bottom