The ImageStyleDownloadController did not resolve correctly the name of the source image, when the Convert effect was added to a style.

What are the steps required to reproduce the bug?

  • Add image style with a convert effect to jpg
  • Upload an png image to the public files root directoryand call the style url

What behavior were you expecting?
See a jpg image

What happened instead?
See a 404 page

CommentFileSizeAuthor
#66 2630230.patch5.54 KBeiriksm
#56 fix-convert-image-effect-2630230-56.patch5.54 KBayushmishra206
#56 interdiff_49-56.patch976 bytesayushmishra206
#51 fix-convert-image-effect-2630230-49.patch5.55 KBvakulrai
#48 interdiff-2630230-45-48.txt1.35 KBmsuthars
#48 fix-convert-image-effect-2630230-48.patch5.55 KBmsuthars
#45 2630230-45.patch5.36 KBayushmishra206
#45 interdiff_37-45.txt2.65 KBayushmishra206
#37 2630230-37.patch5.25 KBmarvin_B8
#37 interdiff_35-37.txt3.36 KBmarvin_B8
#35 2630230-35.patch4.96 KBjjcarrion
#35 interdiff.txt659 bytesjjcarrion
#33 2630230-32.patch4.88 KBvacho
#29 2630230.patch4.63 KBeiriksm
#27 interdiff.txt2.66 KBeiriksm
#27 2630230.txt4.63 KBeiriksm
#20 2630230.patch3.13 KBborisson_
#20 interdiff-2630230.txt605 bytesborisson_
#19 2630230-19-D8.patch3.14 KBmohit1604
#19 interdiff.txt498 bytesmohit1604
#16 interdiff_13-16.txt485 bytesmondrake
#16 2630230-16.patch3.17 KBmondrake
#13 2630230-13-test-only.patch1.91 KBmondrake
#13 2630230-13.patch3.17 KBmondrake
#12 2630230-12.drupal.Image-effect-convert-not-working.patch1.26 KBmikelutz
#3 2630230-fix-convert-image-effect-3.patch1.26 KBchr.fritsch
#2 2630230-fix-convert-image-effect.patch1.08 KBchr.fritsch
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chr.fritsch created an issue. See original summary.

chr.fritsch’s picture

Status: Active » Needs review
FileSize
1.08 KB
chr.fritsch’s picture

This only occurs if the source image is in the root file folder

chr.fritsch’s picture

Ping

mondrake’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs issue summary update

This only occurs if the source image is in the root file folder

So this is an edge case, right? I think this needs to be reflected in the IS, and we definitely need a test to show the bug.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

merauluka’s picture

I don't know if this can truly be considered an edge case. There are plenty of sites that will drop a lot of their file uploads directly into the public file folder instead of organizing them into subfolders. The issue is that the default PHP function pathinfo strips the trailing slashes from the "dirname" which breaks any images being converted to a different image type that are stored in the root public folder.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mikelutz’s picture

This is still an issue, i'm rerolling this patch against 8.5. Still needs tests, but for the record, files in the root of the public folder isn't really an edge case, there are lots of reasons they may be there. My particular case came from a d7-d8 migration, where the files were copied over in the root because that's where they were in D7

mondrake’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
3.17 KB
1.91 KB

Here's a test.

Status: Needs review » Needs work

The last submitted patch, 13: 2630230-13-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mikelutz’s picture

Status: Needs work » Needs review
mondrake’s picture

Title: Image effect convert not working » Image effect convert fails when image file is in the public files root
Issue summary: View changes
Issue tags: -Needs issue summary update
FileSize
3.17 KB
485 bytes

Fixed the PHPCS nit and updated issue title and summary.

borisson_’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/image/tests/src/Functional/ImageEffect/ConvertTest.php
    @@ -0,0 +1,54 @@
    +  /**
    +   * Modules to enable.
    +   *
    +   * @var array
    +   */
    

    Can be replaced by {@inheritdoc}

  2. +++ b/core/modules/image/tests/src/Functional/ImageEffect/ConvertTest.php
    @@ -0,0 +1,54 @@
    +  public static $modules = ['image', 'simpletest'];
    

    Why does this need the simpletest module?

mondrake’s picture

Issue tags: +Novice

#17.2 because there's a drupal_get_path('module', 'simpletest') a few lines below. TBH I do not know if that needs the module to be installed though. If it doesnt than yep that's supefluous.

mohit1604’s picture

Status: Needs work » Needs review
FileSize
498 bytes
3.14 KB

Did changes as per #17 and #18 , please review it :)

borisson_’s picture

#17.2 wasn't fixed. But the test passes with the simpletest module removed from the modules to install.

runeasgar’s picture

I am at the Drupalcon Nashville 2018 mentored sprint. I'm going to review this issue now.

runeasgar’s picture

Unable to reproduce. I receive a 403, not a 404.

The instructions to reproduce are unclear (to me): "call the style url". I don't know what this means. My best interpretation was to hit the direct URL path where the "styled" image should reside. To test this, I created my image style (test_image_style) and changed the Article content type image field to use it for display. I then created an article, added an image, viewed the node, right clicked the image, and opened it in a new tab, which had this URL:

http://sprint-20180413-0916.ddev.local:8080/sites/default/files/styles/t...

I placed a new file, test.png, directly in the /sites/default/files directory, then attempted to access it using these modified URLs:

http://sprint-20180413-0916.ddev.local:8080/sites/default/files/styles/t...
http://sprint-20180413-0916.ddev.local:8080/sites/default/files/styles/t...
http://sprint-20180413-0916.ddev.local:8080/sites/default/files/styles/t...

All resulted in a 403, but I have confirmed that no image files exist at /sites/default/files/styles/test_image_style/public (so, why am I NOT getting a 404?).

Regardless, for kicks, I applied the patch. No change in the above-described behavior.

I assume I'm missing something. I'd be happy to re-test if someone can point out what I'm doing wrong.

mikelutz’s picture

Your 403 comes from the fact that you haven't generated an image token to append to the end to authorize the image style generation. This one is tricky to reproduce because D8 doesn't want to put images in the root of the public files directory.

I haven't tested this, but off the top of my head, to reproduce without custom code, go with your first method, but edit your image field settings and remove [date:custom:Y]-[date:custom:m] from the File directory setting, so that the image is uploaded directly to the public files directory. Then you should get your proper tokenized url where the system cannot convert the file.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mikelutz’s picture

Confirming that this bug still exists in 8.6 and 8.7, and the patch from #20 is still valid and solves the issue. I'm rerunning tests against 8.6 and 8.7, but I touched the patch above, so I can't RTBC.

eiriksm’s picture

Assigned: Unassigned » eiriksm
Status: Needs review » Needs work

This does not work if your default file scheme is private and you are trying to generate an image style for a public file.

file_build_uri ends up calling file_default_scheme. which is not what we want.

Working on this

eiriksm’s picture

Status: Needs work » Needs review
FileSize
4.63 KB
2.66 KB

Not sure if we are allowed to change constructors, but would be nice to actually use a service instead of file_uri_scheme or static container calls.

Lets see if the tests pass at least.

eiriksm’s picture

Assigned: eiriksm » Unassigned
eiriksm’s picture

A bit quick, my patch was not in patch format :D

mikelutz’s picture

Status: Needs review » Needs work

We can change the constructor AFAIK, since controllers use dependency injection. The signature of the create method is unchanged.

It probably needs an additional test testing against your case of a default private scheme and generating a style for a public file.

eiriksm’s picture

Yes i know but if my custom module extends this class my code would break. So it might be a bc breaking change.

Agree with the test. Just wanted to see if the tests passed first :)

mikelutz’s picture

While that is true, controller constructors are not considered part of the API, and are subject to change, so you are all good.

@see https://www.drupal.org/core/d8-bc-policy#constructors

vacho’s picture

Patch rerolled

vacho’s picture

I Sorry patch #32 at comment #33 (first bad) is for 8.8.x version but I note that for this 8.8.x version the issue does not happen

jjcarrion’s picture

Status: Needs work » Needs review
FileSize
659 bytes
4.96 KB

I have tested 8.8.1 without the patch and this is still an issue. The reroll from comment #33 has a missing comma and a syntax error, so I have fixed that missing comma and the patch fixes the issue.

Here is the patch for version 8.8.x and the interdiff against the one from comment #33

Status: Needs review » Needs work

The last submitted patch, 35: 2630230-35.patch, failed testing. View results

marvin_B8’s picture

Status: Needs work » Needs review
FileSize
3.36 KB
5.25 KB

Reroll to fix the unit tests and remove some deprecations.

TwiiK’s picture

We're using this patch with Drupal 8.8.2 in production with success so far. Without this patch png images in the root files folder could not be generated as image styles, with it they work as expected.

Edit: Patch from #37 that is.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

hehongbo’s picture

Also encountered this issue in 8.8.5 after the adoption of responsive image and a series of image styles. Patch #37 works.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

mightyulysses’s picture

Also encountered this issue in 8.9.3. Patch #37 works beautifully.

mondrake’s picture

Version: 8.9.x-dev » 9.1.x-dev
Status: Needs review » Needs work
Issue tags: -Novice +Needs reroll
mondrake’s picture

  1. +++ b/core/modules/image/src/Controller/ImageStyleDownloadController.php
    @@ -51,12 +60,15 @@ class ImageStyleDownloadController extends FileDownloadController {
    -  public function __construct(LockBackendInterface $lock, ImageFactory $image_factory, StreamWrapperManagerInterface $stream_wrapper_manager = NULL) {
    +  public function __construct(LockBackendInterface $lock, ImageFactory $image_factory, StreamWrapperManagerInterface $stream_wrapper_manager = NULL, FileSystemInterface $file_system = NULL) {
         parent::__construct($stream_wrapper_manager);
         $this->lock = $lock;
         $this->imageFactory = $image_factory;
         $this->logger = $this->getLogger('image');
    +    $this->fileSystem = $file_system;
       }
    

    I think we need to make the assignment conditional with deprecation - if $file_system is null, it should be got form \Drupal::service

  2. +++ b/core/modules/image/tests/src/Functional/ImageEffect/ConvertTest.php
    @@ -0,0 +1,58 @@
    +  public static $modules = ['image'];
    

    protected

  3. +++ b/core/modules/image/tests/src/Functional/ImageEffect/ConvertTest.php
    @@ -0,0 +1,58 @@
    +    $this->assertEqual(SAVED_NEW, $image_style->save());
    ...
    +    $this->assertEqual(SAVED_UPDATED, $image_style->save());
    

    assertEquals

  4. +++ b/core/modules/image/tests/src/Functional/ImageEffect/ConvertTest.php
    @@ -0,0 +1,58 @@
    +    $this->assertResponse(200);
    

    $this->assertSession()->statusCodeEquals(200);

ayushmishra206’s picture

Status: Needs work » Needs review
FileSize
2.65 KB
5.36 KB

Made the changes requested in #44. Please review.

mondrake’s picture

Status: Needs review » Needs work
Issue tags: -Needs reroll

Thanks @ayushmishra206!

+++ b/core/modules/image/src/Controller/ImageStyleDownloadController.php
@@ -51,12 +60,18 @@ class ImageStyleDownloadController extends FileDownloadController {
-  public function __construct(LockBackendInterface $lock, ImageFactory $image_factory, StreamWrapperManagerInterface $stream_wrapper_manager = NULL) {
+  public function __construct(LockBackendInterface $lock, ImageFactory $image_factory, StreamWrapperManagerInterface $stream_wrapper_manager = NULL, FileSystemInterface $file_system) {

we cannot have a mandatory argument ($file_system) after an optional one ($stream_wrapper_manager), so $file_system = NULL is correct.

Re #44.1, we should have something like this:

  /**
   * Constructs a ArchiverManager object.
   *
   * @param \Traversable $namespaces
   *   An object that implements \Traversable which contains the root paths
   *   keyed by the corresponding namespace to look for plugin implementations.
   * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
   *   Cache backend instance to use.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler to invoke the alter hook with.
   * @param \Drupal\Core\File\FileSystemInterface $file_system
   *   The file handler.
   */
  public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, FileSystemInterface $file_system = NULL) {
    parent::__construct('Plugin/Archiver', $namespaces, $module_handler, 'Drupal\Core\Archiver\ArchiverInterface', 'Drupal\Core\Archiver\Annotation\Archiver');
    $this->alterInfo('archiver_info');
    $this->setCacheBackend($cache_backend, 'archiver_info_plugins');
    if (!isset($file_system)) {
      @trigger_error('Not defining the final $file_system argument to ' . __METHOD__ . ' is deprecated in drupal:8.8.3 and will throw an error in drupal:10.0.0.', E_USER_DEPRECATED);
      $file_system = \Drupal::service('file_system');
    }
    $this->fileSystem = $file_system;
  }

with a @trigger_error if $file_system is null.

msuthars’s picture

Assigned: Unassigned » msuthars
msuthars’s picture

Assigned: msuthars » Unassigned
Status: Needs work » Needs review
FileSize
5.55 KB
1.35 KB

@ayushmishra206 thanks for the work. I updated the patch as suggested by @mondrake. Please review.

mondrake’s picture

Status: Needs review » Needs work
+++ b/core/modules/image/src/Controller/ImageStyleDownloadController.php
@@ -51,12 +60,20 @@ class ImageStyleDownloadController extends FileDownloadController {
+      @trigger_error('Not defining the final $file_system argument to ' . __METHOD__ . ' is deprecated in drupal:8.8.3 and will throw an error in drupal:10.0.0.', E_USER_DEPRECATED);

deprecated in drupal:9.1.0

vakulrai’s picture

Assigned: Unassigned » vakulrai
vakulrai’s picture

Assigned: vakulrai » Unassigned
Status: Needs work » Needs review
FileSize
5.55 KB

Updated the @trigger_error message by replacing drupal:8.8.3 to drupal:9.1.0.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

Thank you, RTBC - I shouldn't really but #38, #40 and #42 are supporting evidence.

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Bug Smash Initiative
+++ b/core/modules/image/src/Controller/ImageStyleDownloadController.php
@@ -51,12 +60,20 @@ class ImageStyleDownloadController extends FileDownloadController {
+      @trigger_error('Not defining the final $file_system argument to ' . __METHOD__ . ' is deprecated in drupal:9.1.0 and will throw an error in drupal:10.0.0.', E_USER_DEPRECATED);

Nit: what is the use of final here for - we don't normally reference the argument position right?

Also - shouldn't we be adding a new deprecation test for this - per item 3 of https://www.drupal.org/core/deprecation#how

mondrake’s picture

Status: Needs review » Needs work

Per #3170185-14: Drupal\taxonomy\Form\OverviewTerms should determine the current page via the 'pager.manager' service, not from the Request, the deprecation test seems not necessary in this case.

NW to remove the word "final" from

+++ b/core/modules/image/src/Controller/ImageStyleDownloadController.php
@@ -51,12 +60,20 @@ class ImageStyleDownloadController extends FileDownloadController {
+      @trigger_error('Not defining the final $file_system argument to ' . __METHOD__ . ' is deprecated in drupal:9.1.0 and will throw an error in drupal:10.0.0.', E_USER_DEPRECATED);
ayushmishra206’s picture

Assigned: Unassigned » ayushmishra206

Working on #54

ayushmishra206’s picture

Assigned: ayushmishra206 » Unassigned
Status: Needs work » Needs review
FileSize
976 bytes
5.54 KB

Made the change requested in #54. Please review.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 56: fix-convert-image-effect-2630230-56.patch, failed testing. View results

mondrake’s picture

Random fail in #58

mondrake’s picture

Status: Needs work » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

We need a follow-up to fix StreamWrapperManagerInterface $stream_wrapper_manager = NULL - that cannot be NULL - we missed this in #3097453: Remove system.module BC layers

Committed aa12b0e and pushed to 9.1.x. Thanks!

  • alexpott committed aa12b0e on 9.1.x
    Issue #2630230 by mondrake, ayushmishra206, chr.fritsch, eiriksm,...
mondrake’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

maximpodorov’s picture

What about fixing 8.x versions which have this annoying problem too?

eiriksm’s picture

Version: 9.1.x-dev » 8.9.x-dev
FileSize
5.54 KB

Patch applies to 8.9.x as well, but here it is. It's not possible for me to re-open this, but let's discuss if we should fix it first?

Also, the patch includes a text about deprecating in 9.1.x. Should we leave that?