Problem/Motivation
Version: ImageMagick 6.9.10-68 Q16 x86_64
When generating images on our project, performing a conversion to WEBP, we've encountered that during the creation of some images, the following errors/warnings were thrown.
Warning : Undefined array key 1 dans Drupal\imagemagick\Plugin\FileMetadata\ImagemagickIdentify->identify() (/web/modules/contrib/imagemagick/src/Plugin/FileMetadata/ImagemagickIdentify.php ligne 208)
TypeError : trim(): Argument #1 ($string) must be of type string, null given dans trim() (ligne 214 de /web/modules/contrib/imagemagick/src/Plugin/FileMetadata/ImagemagickIdentify.php).
The issue occurs because there is additional output which is retrieved when using the identify command:
Decoded /tmp/magick-6050w68DqfhHR9x9. Dimensions: 328 x 450. Now saving...
Saved file /tmp/magick-60508Ys8A13Dlzsu
format:PAM|width:328|height:450|colorspace:sRGB|profiles:|exif_orientation:As you can see there is a line "Decoded" and "Saved file" inside, which crashes the code later on.
Proposed resolution
A patch is created to allow to filter out all the values that do not contain a pipe sign, to be able to continue.
Remaining tasks
It might be required to review this, maybe the original cause can be fixed in a different way, or there is another solution possible than checking on the pipe sign.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | outback-sunset-fade-2021-32.jpg | 1.44 MB | mach3.zone |
| #2 | imagemagick-image-metadata-cleanup-3432948-0.patch | 795 bytes | hoebekewim |
Issue fork imagemagick-3432948
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
hoebekewim commentedComment #3
hoebekewim commentedComment #4
hoebekewim commentedComment #5
meanderix commentedWe noticed that for some jpeg images the following command was executed:
(Here we're using the graphicsmagick binary, but I guess its the same problem also in imagemagick.)
The array that is returned would look like this:
It seems like token replacement correctly substitutes
[EXIF:Orientation]with a "1", but then it also adds the same value to a new line.ImagemagickIdentify then incorrectly assumes that the lines can be exploded (both with the "|" and the ":" characters).
Comment #6
meanderix commentedThis problem also seems to depend on what PHP version you're using. It looks like we were getting only a deprecation warnings in PHP 8.1 and 8.2, but in 8.3 and 8.4
trim()is now throwing an error.Comment #7
mach3.zone commentedIt definitely throws an error that prevents the node from loading.
In my opinion, preventing a node is a major issue.
The patch works for us. Thanks, @meanderix.
I've attached a sample image for analysis purposes.
Also note, that there is a php warning right before the error:
Comment #8
mondrakeComment #10
mondrakeThank you. All this unexpected text... should it be considered IM or GM buggy behavior? Has anybody checked issue logs?
Anyway, yes it seems like introducing more control in the parsing of identify's output is a good idea.
In the MR, using regex. Also added an unit test with the fail cases reported in the issue.
Comment #12
mondrakeThanks all!