Page 1 of 1

Imagick 1687 upgrade to 1690 errors IO error writing tag data

Posted: 2020-02-20T04:44:25-07:00
by sir8472
After a recent update to my production environment, I seem to be having problems with writing certain TIFF files. I’ve produced a cut-down PHP code snippet that reflects what’s happening in production:

Code: Select all

$img = new Imagick('source_1.png');
$img->setImageFormat('tiff');
$img->setType(\Imagick::IMGTYPE_TRUECOLORMATTE);
$img->transformImageColorspace(\Imagick::COLORSPACE_SRGB);
$img->setImageDepth(8);
file_put_contents('output_fpc', $img→getImageBlob());
This seems to fail silently, but when trying to open the TIFF it claims to be corrupt.

Modifying this code slightly, I’ve been able to produce a run-time error:

Code: Select all

$img = new Imagick('source_1.png');
$img->setImageFormat('tiff');
$img->setType(\Imagick::IMGTYPE_TRUECOLORMATTE);
$img->transformImageColorspace(\Imagick::COLORSPACE_SRGB);
$img->setImageDepth(8);
file_put_contents('output_fpc', $img→getImageBlob());
$img->writeImage('output_igk');
This is the error I’m seeing:

PHP Fatal error: Uncaught ImagickException: IO error writing tag data. `TIFFWriteDirectoryTagData' @ error/tiff.c/TIFFErrors/604

Working Conditions:

Debian Stretch base install with the following changes:

Code: Select all

apt-get update && apt-get install -y php-cli php-imagick

Code: Select all

    PHP 7.0.33-0+deb9u7 (cli) (built: Feb 16 2020 15:11:40) ( NTS )
    [versionNumber] => 1687
    [versionString] => ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org

Failure Conditions:

Debian Buster base install with the following changes:

Code: Select all

apt-get update && apt-get install -y php-cli php-imagick

Code: Select all

    PHP 7.3.14-1~deb10u1 (cli) (built: Feb 16 2020 15:07:23) ( NTS )
    [versionNumber] => 1690
    [versionString] => ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org
Files with embedded offsets seem to be more likely to fail.

I've attached some affected files here, but it is a temporary link (open to a better way to share files!):
https://send.firefox.com/download/7cc3b ... giY_voPJsQ

As I see it, there's two potential workarounds:
1. Maintain an older version of Debian/Imagick
2. Rewrite the core of the project's file storage to allow writeImage() to be passed instead of getImageBlob()

Re: Imagick 1687 upgrade to 1690 errors IO error writing tag data

Posted: 2020-02-20T10:01:56-07:00
by fmw42
Is the issue with Imagick or Imagemagick? Can you run the equivalent command in a terminal window in command line code or via PHP exec() to test?

Re: Imagick 1687 upgrade to 1690 errors IO error writing tag data

Posted: 2020-02-21T02:22:31-07:00
by sir8472
Apologies, I'm still finding my way around the forums. This is issue relates to imagick, the PHP implementation only. I'm able to run the following command and generate a TIFF file without issue:

Code: Select all

convert -format tiff -type TrueColorAlpha -colorspace sRGB -depth 8 storage/app/raw/2020/2/19/704608e4d1c1dad6cfba95a589a9f55f_5e4d468961ed1 output_cli