ImageStyleDownloadController::deliver() when checks for source image existence for a style converting extension uses derivative scheme instead of source

Created on 12 July 2021, over 3 years ago
Updated 6 May 2024, 8 months ago

Problem/Motivation

\Drupal\image\Controller\ImageStyleDownloadController::deliver() contains the following code:

$path_info = pathinfo(StreamWrapperManager::getTarget($image_uri));
$converted_image_uri = sprintf('%s://%s%s%s', $this->streamWrapperManager->getScheme($derivative_uri), $path_info['dirname'], DIRECTORY_SEPARATOR, $path_info['filename']);
if (!file_exists($converted_image_uri)) {
  // ...
}

Though cannot find issues caused by this code in the core, I suppose that scheme should be extracted from the $image_uri variable instead.

Looks this causes issue in the Remote Stream Wrapper module, for example: image style derivative generation will fail if a style converts image extension (the module itself needs patching from here: 🐛 Image styles setting extension cause access denied Needs review ).

I also think that there is some inconsistency with using both StreamWrapperManager::... and $this->streamWrapperManager->...

Initially this code was introduced here: #2630230: Image effect convert fails when image file is in the public files root

Proposed resolution

Use $this->streamWrapperManager->getScheme($image_uri) as a second argument for the sprintf() call.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Image system 

Last updated 1 day ago

Created by

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024