Avoid warning from imagecreatefrompng when loading png with obscure iCCP profiles

Created on 2 February 2022, over 2 years ago
Updated 14 May 2024, 4 days ago

Problem/Motivation

When a PNG (and some other rarely used formats) image contains iCCP chunk with sRGB IEC61966-2.1 color profile, libpng triggers warning:

Warning: imagecreatefrompng(): gd-png: libpng warning: iCCP: known incorrect sRGB profile in Drupal\system\Plugin\ImageToolkit\GDToolkit->load() (line 201 of core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php).

This warning is printed for any such image, but they're still valid and displayed correctly.

Steps to reproduce

You need an image with iCCP chunk in it and sRGB IEC61966-2.1 color profile. You can achieve this in several ways.

You can find this color profile in attachments for that issue โ€” sRGB IEC61966-2.1.zip โ†’ . Extract it first to get .icc profile.

For examples, I will use core/tests/fixtures/files/image-test.png. It will be called image-test.png in commands below without full path.

ImageMagick CLI (convert)

Assuming that color profile (.icc) and image (image-test.png) in the same folder.

  1. convert image-test.png -profile sRGB\ IEC61966-2.1.icc -strip -profile sRGB\ IEC61966-2.1.icc -define png:include-chunk=zTXt,iCCP image-1-icpp.png
  2. Upload this image into Drupal and try to process it by any image style.

GIMP (OpenSource image editor)

  1. Open image-test.png in GIMP.
  2. Go to Image | Color Management | Assign Color Profileโ€ฆ
  3. In Assign section in select element chose Select color profile from diskโ€ฆ
  4. Select downloaded .icc profile.
  5. Click Assign.
  6. Save the image by File | Save as chose name and path and click Export. In open modal window, make sure you have checked Save color profile, and then again Export.
  7. Upload this image into Drupal and try to process it by any image style.

Proposed resolution

Add @ symbol before calling imagecreatefrompng() to suppress this warning.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

๐Ÿ› Bug report
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Image systemย  โ†’

Last updated 2 days ago

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia someshver Panchkula

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request โ†’ as a guide.

    Could you please provide steps/configuration taken to recreate this.
    This will need a test case showing the issue.

    Thanks

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jenlampton

    I was able to recreate this by uploading a .webp image into an image/media reference field, and then rendering it using an image style.

  • Status changed to Needs review about 1 year ago
  • ๐Ÿ‡ท๐Ÿ‡บRussia Niklan Russia, Perm

    I was able to extract the broken color profile from the image and apply it to another one and trigger that error in tests. The broken color profile called sRGB IEC61966-2.1. I'm attaching it as well, so you can test it by yourself on any image (by injecting it using CLI tools or image editors like GIMP, Krita, etc).

    I'm also switch versions to 10.1.x, because patch from #8 wonโ€™t apply on 10.0.x branch. And I focus initially on future branch, if it's needed it can be backported later on.

  • ๐Ÿ‡ท๐Ÿ‡บRussia Niklan Russia, Perm

    Updated issue summary with steps to reproduce this problem.

  • ๐Ÿ‡ท๐Ÿ‡บRussia Niklan Russia, Perm

    Added cspell ignore for iCCP

  • ๐Ÿ‡ท๐Ÿ‡บRussia Niklan Russia, Perm

    Sorry for noise, patch in #20 contains .icc profile by accident. This one is clean patches.

  • ๐Ÿ‡ท๐Ÿ‡บRussia Niklan Russia, Perm

    Gosh ๐Ÿคฏ

    Anyway, since I need to create patches again, I generated a test image using convert instead of GIMP. It is smaller, because there is no GIMP metadata in it.

    ๐Ÿคž

  • ๐Ÿ‡ท๐Ÿ‡บRussia Chi

    Personally, I would not create tests for suppression operators. Such tests are too tricky.
    Also, I think it needs a comment explaining what kind of errors could happen without the suppression.

  • ๐Ÿ‡ท๐Ÿ‡บRussia Niklan Russia, Perm

    Added comment for suppression call.

    Disabled tests, because the only difference from #22 is comment.

  • ๐Ÿ‡ฉ๐Ÿ‡ฐDenmark mudassar774

    Re-rolled patch #3 to make it work with 9.5.5

  • Status changed to RTBC about 1 year ago
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia jannakha Brisbane!

    #26 works! no more warning on d 9.5.5/php 8.1.1
    thank you!

  • Status changed to Needs work about 1 year ago
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone New Zealand

    The issue title is used as the commit message and it should state what this issue resolves instead of being a long error message.

    Do we really want to suppress all warnings?

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia alex.skrypnyk Melbourne

    Backporting #8 to D7

  • Status changed to Needs review 10 months ago
  • last update 10 months ago
    2,159 pass
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States neclimdul Houston, TX

    Better title.

    Do we really want to suppress all warnings?

    I had the same question, but I'm not sure what options we're really given. I suspect this is probably OK though because real problems will throw and exception which gets caught and logged. At least in the 10.x versions of this patch.

    That said, the block we're adjusting is generalized for all image formats but the comment clearly only addresses the impact on PNGs. Very bikesheddy but maybe we should probably adjust the documentation to match the scope of the code not the scope of this issue. Something like this?

          // Suppress warnings from image creation because there is a possibility
          // that source images contain data that would trigger non-fatal warnings
          // we can't handle. For example, a PNG saved with 'sRGB IEC61966-2.1'
          // color profile has 'iCCP' chunk data which is not recognized on most
          // systems and will cause libpng to trigger warnings but otherwise do not
          // affect image processing.
    
  • Status changed to Needs work 10 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Looking at #25 and should the test go into ToolkitGdTest?

    Also reading the last comment 31 think expanding to match makes sense. Least I can't think of a reason not to.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium DieterHolvoet Brussels

    Rerolled the last patch against 11.x.

  • 53:57
    53:13
    Running
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mmenavas

    Rerolled the last patch against 10.1.2

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update 9 months ago
    Patch Failed to Apply
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States ricksta

    I confirm the patch in 34 ๐Ÿ› Avoid warning from imagecreatefrompng when loading png with obscure iCCP profiles Needs work works for Drupal 10.

  • last update 7 months ago
    29,672 pass
  • Status changed to RTBC 7 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mark_fullmer Tucson

    Based on the comment from #35, I'm changing the status to RTBC.

  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States neclimdul Houston, TX

    Based on the rest of the comments and the lack of tests don't think this is actually ready. There aren't even tests on the last couple patches.

    re: #32 what the heck is that test. Its not in the system module, its in the wrong location based on the namespace of the class, the file name doesn't align with the tested class? Something weird going on there but it does look like that's where existing tests are.

  • last update 6 months ago
    Custom Commands Failed
  • Status changed to Needs work 6 months ago
  • The Needs Review Queue Bot โ†’ tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • last update 6 months ago
    29,686 pass
  • last update 6 months ago
    29,686 pass
  • First commit to issue fork.
  • Pipeline finished with Failed
    5 months ago
    #63494
  • Pipeline finished with Failed
    5 months ago
    #63497
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine Taran2L Lviv

    Taran2L โ†’ changed the visibility of the branch 3261924-avoid-warning-from to hidden.

  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine Taran2L Lviv

    Taran2L โ†’ changed the visibility of the branch png-11.x to hidden.

  • Pipeline finished with Failed
    5 months ago
    Total: 200s
    #65334
  • Pipeline finished with Success
    5 months ago
    Total: 935s
    #65336
  • Status changed to Needs review 5 months ago
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine Taran2L Lviv
  • Pipeline finished with Success
    5 months ago
    #65353
  • Status changed to Needs work 5 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    1 small feedback item.

    Hiding patches for clarity.

  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine Taran2L Lviv

    @smustgrave I disagree, the dictionary already has all the wierd words ...

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Which is actively trying to be cleaned up

  • Status changed to Needs review 5 months ago
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine Taran2L Lviv

    Question: is it possible to resolve threads ?

  • Pipeline finished with Success
    5 months ago
    #66733
  • Status changed to RTBC 5 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave
    There was 1 error:
    1) Drupal\KernelTests\Core\Image\ToolkitGdTest::testIncorrectIccpSrgbProfile with data set "PNG with iCCP profile" ('core/tests/fixtures/files/ima...le.png')
    PHPUnit\Framework\Exception: PHP Warning:  imagecreatefrompng(): gd-png: libpng warning: iCCP: known incorrect sRGB profile in /builds/issue/drupal-3261924/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php on line 271
    Warning: imagecreatefrompng(): gd-png: libpng warning: iCCP: known incorrect sRGB profile in /builds/issue/drupal-3261924/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php on line 271
    /builds/issue/drupal-3261924/vendor/phpunit/phpunit/src/Framework/TestSuite.php:684
    /builds/issue/drupal-3261924/vendor/phpunit/phpunit/src/Framework/TestSuite.php:684
    /builds/issue/drupal-3261924/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:651
    /builds/issue/drupal-3261924/vendor/phpunit/phpunit/src/TextUI/Command.php:144
    /builds/issue/drupal-3261924/vendor/phpunit/phpunit/src/TextUI/Command.php:97
    ERRORS!
    Tests: 97, Assertions: 1197, Errors: 1.
    

    Verified test coverage using test-only feature.

    All feedback has been addressed.

    @Taran2L as far as threads, as the opener of the thread I use to be able to close myself but that no longer seems to be the case. Think only the person who opened the MR can resolve threads now.

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone New Zealand

    I'm triaging RTBC issues โ†’ . I read the IS, the comments and the MR. Thanks for the issue summary. As someone who doesn't work with images it was very clear and easy to understand the problem. I didn't find any unanswered questions.

    I read the MR (not a code review) and there is minor work to do on the comments.

  • Status changed to Needs work 5 months ago
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone New Zealand

    Oh sorry, @neclimdul, thank you for answering my question in #31.

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands Wilfred Waltman

    Rerolled patch from #34 for Drupal 10.2

  • last update 5 months ago
    25,813 pass, 1,797 fail
  • 12:05
    10:05
    Running
  • last update 5 months ago
    25,783 pass, 1,835 fail
  • last update 5 months ago
    25,761 pass, 1,823 fail
  • Pipeline finished with Failed
    4 months ago
    #73447
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine Taran2L Lviv

    Taran2L โ†’ changed the visibility of the branch 10.2.x to hidden.

  • Pipeline finished with Failed
    4 months ago
    Total: 164s
    #73458
  • Status changed to Needs review 4 months ago
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine Taran2L Lviv

    Feedback has been addressed

    Also, attaching a static patch from the latest changes in the MR (for composer patching purposes)

  • Status changed to Needs work 4 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    MR appears to have failures.

  • Status changed to Needs review 4 months ago
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine Taran2L Lviv
  • Status changed to RTBC 4 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Feedback appears to have been addressed

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia Nigel Cunningham Geelong

    Attaching static version of MR for composer patch.

  • Status changed to Needs work 3 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    The test doesn't work for me locally. With or without the change to GDToolkit I get:

    Testing Drupal\KernelTests\Core\Image\ToolkitGdTest
    ..E                                                                 3 / 3 (100%)
    
    Time: 00:03.934, Memory: 4.00 MB
    
    There was 1 error:
    
    1) Drupal\KernelTests\Core\Image\ToolkitGdTest::testIncorrectIccpSrgbProfile with data set "PNG with iCCP profile" ('core/tests/fixtures/files/ima...le.png')
    PHPUnit\Framework\Exception: libpng warning: iCCP: known incorrect sRGB profile
    
  • Pipeline finished with Success
    3 months ago
    Total: 2524484s
    #73630
  • Pipeline finished with Success
    3 months ago
    #89108
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine Taran2L Lviv

    @longwave this is very weird - it does not work on my local as well ... but it seems it does work on CI, weird

    I think the value of the test is that error is being suppressed.

  • Pipeline finished with Success
    3 months ago
    Total: 483s
    #98526
  • ๐Ÿ‡ท๐Ÿ‡บRussia Niklan Russia, Perm

    Hello again. I see some folks not very happy with silencing all the errors from that call. I understand that as well, it can be helpful sometimes. Without it, I won't be found this issue as well. Maybe we wrap this call $image = @$function($this->getSource()); by a condition?

    We have already configuration `system.logging` with `error_level` setting. Maybe we will do it like:

    if ($error_level === 'verbose') {
      $image = $function($this->getSource());
    }
    else {
      $image = @$function($this->getSource());
    }
    

    This allows a developer to find out that there is a problem, but it won't be logged and showed on production instances. It might be looking ugly, but it solves most of the concerns here. Currently, as I remember correctly (I've already fixed that images), this will be logged on production on every over page with a broken image when it's processed for the first time (if no style yet created). In some cases, it can create a lot of useless noise in the logging system.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States generalredneck

    It IS possible to handle warnings, and therefore forego suppressing them all, but it would require setting up an error handler to do it. That said, if we are worried about particular image profiles, is there a way to whitelist some and check to see if the image is what we want? Is that too process intensive?

    Trying to throw some fresh ideas at this that I didn't see in the comments. I do like Niklan's thoughts though.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States neclimdul Houston, TX

    I think the concerns might be a bit overstated. Actual problems will trigger real exceptions that get logged. This just avoids warnings that shouldn't be triggered. If I remember correctly they're warnings triggered by the underlying libraries so they don't actually follow PHP's documentation for the method.

  • First commit to issue fork.
  • Pipeline finished with Failed
    14 days ago
    Total: 583s
    #164211
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia VladimirAus Brisbane, Australia

    Resolved MR conflict and added patches for D10 and D11.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States rraney

    Just curious about Patch 65. What's all the garbage text at the end of the file?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States generalredneck

    That's a new file... png based on the diff.

    diff --git a/core/tests/fixtures/files/image-test-iccp-profile.png b/core/tests/fixtures/files/image-test-iccp-profile.png
    new file mode 100644
    index 0000000000000000000000000000000000000000..29cb8945f8e4c1ae40de24bf888715e4d870a164
    --- /dev/null
    +++ b/core/tests/fixtures/files/image-test-iccp-profile.png
    @@ -0,0 +1,24 @@
    +โ€ฐPNG
    
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia VladimirAus Brisbane, Australia

    Trying to bring all changed into new branch as pull from 11.x returns too many merge conflict. ๐Ÿคทโ€โ™€๏ธ
    Also, changing branch to 11.0.x

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia VladimirAus Brisbane, Australia

    VladimirAus โ†’ changed the visibility of the branch 3261924-avoid-warning-from-d11.0 to hidden.

  • Pipeline finished with Failed
    4 days ago
    Total: 189s
    #172280
Production build 0.67.2 2024