Bug with Imagemagick / PHP

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
kenaddams42
Posts: 2
Joined: 2015-11-01T11:32:12-07:00
Authentication code: 1151

Bug with Imagemagick / PHP

Post by kenaddams42 »

Hi All,

When I call Imagick on some "malformed" PDF files, I cannot catch the error.

My PHP script hangs and never exits.

Code: Select all

try {
    echo " . New imagick($identifyfile)...\n";
    $pdf = new imagick($identifyfile);
} catch (ImagickException $e)     {
    var_dump($e);
    die("Stop : Imagick");
}
How can I catch this kind of error, or check the PDF doesn’t contain any blocking error ?

Here is the error text :
  • **** Warning: An error occurred while reading an XREF table.
    **** The file has been damaged. This may have been caused
    **** by a problem while converting or transfering the file.
    **** Ghostscript will attempt to recover the data.
    warning: ignoring zlib error: incorrect data check
    **** Warning: can't process font stream, loading font by the name.
    **** Error reading a content stream. The page may be incomplete.
    **** File did not complete the page properly and may be damaged.
    warning: ignoring zlib error: incorrect data check
    **** Warning: can't process font stream, loading font by the name.
    **** Error reading a content stream. The page may be incomplete.
    **** File did not complete the page properly and may be damaged.
    **** Unknown operator: '608.77.00675' looks like a malformed number, replacing with 0.
    **** Unknown operator: '841.895.865' looks like a malformed number, replacing with 0.
    **** Unknown operator: '0.01-0.148' looks like a malformed number, replacing with 0.
    **** Unknown operator: '5.2627Q'
    **** Unknown operator: '-0.7.08m'
    **** Unknown operator: '5.44.2958' looks like a malformed number, replacing with 0.
    **** Unknown operator: '8m'
    **** Unknown operator: '1-0.101' looks like a malformed number, replacing with 0.
    **** Unknown operator: 'v5-0.017'
    **** Unknown operator: '-0.00-0.039' looks like a malformed number, replacing with 0.
    **** Warning: Invalid operator '-' is assumed to be a number 0.
    **** Warning: Invalid operator '-' is assumed to be a number 0.
    **** Unknown operator: '-v'
    **** Unknown operator: 'l247.0067'
    **** Unknown operator: '-0.003046-0.025' looks like a malformed number, replacing with 0.
    **** Unknown operator: 'c4c'
    **** Unknown operator: 'c002'
    **** Unknown operator: '0.018890.369' looks like a malformed number, replacing with 0.
    **** Unknown operator: '9c'
    **** Unknown operator: 'l597.00674320'
    **** Unknown operator: 'ccm'
    **** Unknown operator: '-0.08cm'
    **** Unknown operator: '6-0.005863' looks like a malformed number, replacing with 0.
    **** Unknown operator: '0.01-0.148' looks like a malformed number, replacing with 0.
    **** Unknown operator: '2-323' looks like a malformed number, replacing with 0.
    **** Unknown operator: '-32cm'
    **** Unknown operator: '0.537.6465.0067464' looks like a malformed number, replacing with 0.
    **** Unknown operator: 'c1'
    **** Error reading a content stream. The page may be incomplete.
    **** File did not complete the page properly and may be damaged.
    **** Unknown operator: '-0.4-1.4.102' looks like a malformed number, replacing with 0.
    **** Unknown operator: '0q'
    **** Unknown operator: '2c'
    **** Unknown operator: 'l85234'
    **** Unknown operator: 'l7S'
    **** Unknown operator: '1q'
    **** Error reading a content stream. The page may be incomplete.
    **** File did not complete the page properly and may be damaged.
    **** Unknown operator: '232.w'
    **** Unknown operator: '-0.051.12' looks like a malformed number, replacing with 0.
    **** Unknown operator: 'm1'
    **** Unknown operator: '2.065..363c'
    **** Unknown operator: '-42.065.' looks like a malformed number, replacing with 0.
    **** Unknown operator: '4.9.0' looks like a malformed number, replacing with 0.
    **** Unknown operator: '2944.524.918' looks like a malformed number, replacing with 0.
    **** Unknown operator: 'l40'
    **** Error reading a content stream. The page may be incomplete.
    **** File did not complete the page properly and may be damaged.
    **** Unknown operator: 'l-0.723'
    **** Unknown operator: 'l-0.139'
    **** Unknown operator: 'l-0.133-0.047'
    **** Unknown operator: 'l-0.133-0.649'
    **** Unknown operator: 'l-0.139'
    **** Unknown operator: '0.515-0.197' looks like a malformed number, replacing with 0.
    **** Unknown operator: '363..262' looks like a malformed number, replacing with 0.
    **** Unknown operator: 'l-0.173-0.047'
    **** Unknown operator: 'l-0.173-0.657'
    **** Unknown operator: '0.515-0.138' looks like a malformed number, replacing with 0.
    **** Unknown operator: '3-6.7935' looks like a malformed number, replacing with 0.
    **** Unknown operator: 'm-1.479'
    **** Unknown operator: '0.035-0.146' looks like a malformed number, replacing with 0.
    **** Unknown operator: 'l-00723'
    **** Unknown operator: '0lm'
    **** Unknown operator: 'l-0.523'
    **** Unknown operator: 'l-00723'
    **** Unknown operator: '-0135-0.423' looks like a malformed number, replacing with 0.
    **** Unknown operator: '0lm'
    **** Unknown operator: '0lm'
    **** Unknown operator: '0lm'
    **** Unknown operator: '0.010lm'
    **** Unknown operator: '0.010lm'
    **** Unknown operator: '0.010lm'
    **** Unknown operator: '0.010lm'
    **** Unknown operator: '0lm'
    **** Unknown operator: '0lm'
    **** Unknown operator: '0lm'
My version is the following :
Any idea please for how to catch this error, or how to detect PDF is malformed *before* the error occurs ?

Thank you,
K.A.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Bug with Imagemagick / PHP

Post by fmw42 »

Delegates (built-in):
It appears you have built IM without any delegate libraries such as for PNG, TIFF, JPG, PDF, etc
kenaddams42
Posts: 2
Joined: 2015-11-01T11:32:12-07:00
Authentication code: 1151

Re: Bug with Imagemagick / PHP

Post by kenaddams42 »

You are right, I upgraded ImageMagick before posting in this forim to check if the bug was corrected in the latest version.

Anyway, you can check now I got the delegates :

Code: Select all

Version: ImageMagick 6.9.2-5 Q16 x86_64 2015-11-01 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC OpenMP
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr lzma openexr pangocairo png tiff wmf x xml zlib
So I just checked to convert a PDF file to JPG, it worked on a first PDF :

Code: Select all

# convert ./S50145326/S50145326.pdf foo.jpg
# ll foo-*
-rw-r--r-- 1 root root  34125 Nov  1 21:54 foo-0.jpg
-rw-r--r-- 1 root root  41342 Nov  1 21:54 foo-10.jpg
-rw-r--r-- 1 root root  69734 Nov  1 21:54 foo-11.jpg
-rw-r--r-- 1 root root  45001 Nov  1 21:54 foo-12.jpg
-rw-r--r-- 1 root root  47790 Nov  1 21:54 foo-13.jpg
-rw-r--r-- 1 root root  58779 Nov  1 21:54 foo-14.jpg
-rw-r--r-- 1 root root  66049 Nov  1 21:54 foo-15.jpg
-rw-r--r-- 1 root root  77299 Nov  1 21:54 foo-16.jpg
-rw-r--r-- 1 root root  40018 Nov  1 21:54 foo-17.jpg
-rw-r--r-- 1 root root   4970 Nov  1 21:54 foo-18.jpg
-rw-r--r-- 1 root root   6515 Nov  1 21:54 foo-19.jpg
-rw-r--r-- 1 root root 202994 Nov  1 21:54 foo-1.jpg
-rw-r--r-- 1 root root 164793 Nov  1 21:54 foo-2.jpg
-rw-r--r-- 1 root root  60147 Nov  1 21:54 foo-3.jpg
-rw-r--r-- 1 root root  83852 Nov  1 21:54 foo-4.jpg
-rw-r--r-- 1 root root  66606 Nov  1 21:54 foo-5.jpg
-rw-r--r-- 1 root root  66652 Nov  1 21:54 foo-6.jpg
-rw-r--r-- 1 root root  65427 Nov  1 21:54 foo-7.jpg
-rw-r--r-- 1 root root  68638 Nov  1 21:54 foo-8.jpg
-rw-r--r-- 1 root root  34765 Nov  1 21:54 foo-9.jpg

Now, back on the previous malformed PDF:

Code: Select all

# convert 4_pub.pdf foo.jpg
   **** Warning:  An error occurred while reading an XREF table.
   **** The file has been damaged.  This may have been caused
   **** by a problem while converting or transfering the file.
   **** Ghostscript will attempt to recover the data.
   **** Unknown operator: '467.690.228' looks like a malformed number, replacing with 0.
   **** Unknown operator: 'cm1.006'
   **** Unknown operator: '0.2m'
   **** Unknown operator: '0.47.144-0.024' looks like a malformed number, replacing with 0.
   **** Unknown operator: '-0566144-0794' looks like a malformed number, replacing with 0.
   **** Unknown operator: '-0.60.2482.3581' looks like a malformed number, replacing with 0.
   **** Unknown operator: '0.m'
   **** Unknown operator: '53.2483cm'
   **** Unknown operator: '0.4342483c735'
   **** Unknown operator: '0.228.2483c97'
   **** Unknown operator: 'Q1.144'
   **** Unknown operator: '-0.65Q'
   **** Unknown operator: '400.67683cm'
   **** Unknown operator: '-0.0220.155' looks like a malformed number, replacing with 0.
   **** Unknown operator: '0.67.' looks like a malformed number, replacing with 0.
   **** Unknown operator: '23Q'
   **** Unknown operator: '425.58515.604' looks like a malformed number, replacing with 0.
   **** Unknown operator: '1Q'
   **** Unknown operator: '4S'
   **** Unknown operator: 'Q68515.389'
   **** Unknown operator: 'S881'
   **** Unknown operator: '1480.55515.50' looks like a malformed number, replacing with 0.
   **** Unknown operator: '-0.0240.05' looks like a malformed number, replacing with 0.
   **** Unknown operator: '0.098c'
   **** Unknown operator: 'Q1Q'
   **** Unknown operator: '1480.55515.794' looks like a malformed number, replacing with 0.
   **** Unknown operator: '465.58515.739' looks like a malformed number, replacing with 0.
   **** Unknown operator: 'Q508'
   **** Unknown operator: '-0.05300.0270.025' looks like a malformed number, replacing with 0.
   **** Unknown operator: '-0.0220.155' looks like a malformed number, replacing with 0.
   **** Unknown operator: '0.67.' looks like a malformed number, replacing with 0.
   **** Unknown operator: '23Q'
   **** Unknown operator: 'c5'
   **** Unknown operator: '-0.2230.077' looks like a malformed number, replacing with 0.
   **** Unknown operator: '1Q'
   **** Unknown operator: '4S'
   **** Unknown operator: 'Q68514cm'
   **** Unknown operator: '-0018c'
   **** Unknown operator: 'S881'
   **** Unknown operator: '0.261c'
   **** Unknown operator: '1Q'
   **** Unknown operator: '343.73121480.55514cm'
   **** Unknown operator: '0.05c'
   **** Unknown operator: '0.098c'
   **** Unknown operator: 'Q1Q'
   **** Unknown operator: '403.24221480155514c737'
   **** Unknown operator: '465755514c68080'
   **** Unknown operator: 'Q58'
   **** Unknown operator: '067663c7092'
   **** Unknown operator: '-0.05300.0270.02270.03' looks like a malformed number, replacing with 0.
   **** Unknown operator: '0.00.0220.155' looks like a malformed number, replacing with 0.
   **** Unknown operator: '-0.4Q'
   **** Unknown operator: '477.58363c489'
   **** Unknown operator: '0.2134c'
   **** Unknown operator: '1Q'
   **** Unknown operator: '4S'
   **** Unknown operator: '758363c272'
   **** Unknown operator: '-0018c'
   **** Unknown operator: 'S887'
   **** Unknown operator: '0.263c'
   **** Unknown operator: '1Q'
   **** Unknown operator: '343.73121480.55513.389' looks like a malformed number, replacing with 0.
   **** Unknown operator: '-0.6370.05c'
   **** Unknown operator: 'Q.0'
   **** Unknown operator: '297c'
   **** Unknown operator: 'Q1.1q'
   **** Unknown operator: '343.73121480258363c67890'
   **** Unknown operator: '465755513c62.37'
   **** Unknown operator: '-0.15c'
   **** Unknown operator: 'Q008'
   **** Unknown operator: '0.06270.031' looks like a malformed number, replacing with 0.
   **** Unknown operator: '0.00.0220.155' looks like a malformed number, replacing with 0.
   **** Unknown operator: '-0.4Q'
   **** Unknown operator: '0.03Q'
   **** Unknown operator: '02cm'
   **** Unknown operator: '4S'
   **** Unknown operator: 'Q6851'
   **** Unknown operator: '-0018c'
   **** Unknown operator: 'S886'
   **** Unknown operator: '0.261c'
   **** Unknown operator: '1Q'
   **** Unknown operator: '02c33120'
   **** Unknown operator: '-0.0240.05c'
   **** Unknown operator: '0.097c'
   **** Unknown operator: 'Q1Q'
   **** Unknown operator: '1480258362c62.37'
   **** Unknown operator: 'Q008'
   **** Unknown operator: '-0.0220.158' looks like a malformed number, replacing with 0.
   **** Unknown operator: '-06Q'
   **** Unknown operator: '1Q'
   **** Unknown operator: '4S'
   **** Unknown operator: '-0018c'
   **** Unknown operator: 'S881'
   **** Unknown operator: '-0.6370.05' looks like a malformed number, replacing with 0.
   **** Unknown operator: '0.098c'
   **** Unknown operator: 'Q1Q'
   **** Unknown operator: '403.24221480258360.66367' looks like a malformed number, replacing with 0.
   **** Unknown operator: 'Q508'
   **** Unknown operator: '-0.05300.08' looks like a malformed number, replacing with 0.
   **** Unknown operator: '-0.621.1041' looks like a malformed number, replacing with 0.
   **** Unknown operator: '0.237c'
   **** Unknown operator: '1Q'
   **** Unknown operator: '4S'
   **** Unknown operator: '75836-0.9' looks like a malformed number, replacing with 0.
   **** Unknown operator: '-0018c'
   **** Unknown operator: 'S887'
   **** Unknown operator: '0c'
   **** Unknown operator: '0.051c'
   **** Unknown operator: 'Q.0'
   **** Unknown operator: '296c'
   **** Unknown operator: 'Q1Q'
   **** Unknown operator: '465.58510.448' looks like a malformed number, replacing with 0.
   **** Unknown operator: '-0.3c'
   **** Unknown operator: 'Q508'
   **** Unknown operator: '59m'
   **** Unknown operator: '23Q'
   **** Unknown operator: '59m26890'
   **** Unknown operator: '1Q'
   **** Unknown operator: '4S'
   **** Unknown operator: 'Q68559m.2010'
   **** Unknown operator: '-0018c'
   **** Unknown operator: 'S886'
   **** Unknown operator: '0.261c'
   **** Unknown operator: '1Q'
   **** Unknown operator: '343.73121480258359m155'
   **** Unknown operator: '0.05c'
   **** Unknown operator: '0l'
   **** Unknown operator: '296c'
   **** Unknown operator: 'Q1Q'
   **** Unknown operator: '403.24221480258359m'
   **** Unknown operator: '59m389'
   **** Unknown operator: 'Q58'
   **** Unknown operator: '-0.0220.158' looks like a malformed number, replacing with 0.
   **** Unknown operator: '0.237c'
   **** Unknown operator: '1Q'
   **** Unknown operator: '4S'
   **** Unknown operator: '-002c'
   **** Unknown operator: 'S881'
   **** Unknown operator: '0.26c'
   **** Unknown operator: '1Q'
   **** Unknown operator: '343.731214802583580.9' looks like a malformed number, replacing with 0.
   **** Unknown operator: '-0.0240.05c'
   **** Unknown operator: '0.097c'
   **** Unknown operator: 'Q1Q'
   **** Unknown operator: '-0.17c'
   **** Unknown operator: 'Q5080'
   **** Unknown operator: '0.23Q'
   **** Unknown operator: '403.54882051.58357.12810' looks like a malformed number, replacing with 0.
   **** Unknown operator: '6S'
   **** Unknown operator: '0.367c'
   **** Unknown operator: 'Q1.20504406177'
   **** Unknown operator: '-0.0140.25' looks like a malformed number, replacing with 0.
   **** Unknown operator: '-0402c'
   **** Unknown operator: 'S864'
   **** Unknown operator: '-080Q'
   **** Unknown operator: '-02Q58'
   **** Unknown operator: '343.73123.835' looks like a malformed number, replacing with 0.
   **** Unknown operator: '-4Q'
   **** Unknown operator: '0..034q'
   **** Unknown operator: '403.54882084084505.139' looks like a malformed number, replacing with 0.
   **** Unknown operator: 'S3084l'
   **** Unknown operator: '004l'
   **** Warning: Invalid operator '-' is assumed to be a number 0.
   **** Warning: Invalid operator '-' is assumed to be a number 0.
   **** Unknown operator: '61Q'
   **** Unknown operator: '0442l'
   **** Unknown operator: '0l'
   **** Unknown operator: '403.54880.3.186505.0402c'
   **** Unknown operator: '-0105c'
   **** Unknown operator: 'QQ'
   **** Unknown operator: '-0326cl'
   **** Unknown operator: '-04084l'
   **** Unknown operator: '-05064l'
   **** Unknown operator: '0.253Q'
   **** Unknown operator: '-0526cl'
   **** Unknown operator: '2c697c'
   **** Unknown operator: '-4Q'
   **** Unknown operator: '403.54882.2631' looks like a malformed number, replacing with 0.
   **** Unknown operator: '-0.4504l'
   **** Unknown operator: '-03.1-0.231' looks like a malformed number, replacing with 0.
   **** Unknown operator: '-0.05300.07' looks like a malformed number, replacing with 0.
   **** Unknown operator: '-0.081220.154' looks like a malformed number, replacing with 0.
   **** Unknown operator: '226c'
   **** Unknown operator: '0Q'
   **** Unknown operator: '-0.26c'
   **** Unknown operator: '-0.06c'
   **** Unknown operator: 'S82'
   **** Unknown operator: 'S010'
   **** Unknown operator: '403.54882051.5858' looks like a malformed number, replacing with 0.
   **** Unknown operator: '-0.05300.01' looks like a malformed number, replacing with 0.
   **** Unknown operator: 'Q.0'
   **** Unknown operator: '-0.05Q'
   **** Unknown operator: 'S02022-0.154'
So if my PHP script tries to automatically convert such kind of malformed PDF, the script hangs.

Is there a way to check what is wrong with these PDF files and why does the error cannot be catched ? I can send you the PDF files if needed for troubleshooting.

Thank you for your help,
++
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Bug with Imagemagick / PHP

Post by fmw42 »

I would not know how. The error is in the Ghostscript delegate that IM uses to read PDFs. What version of Ghostscript do you have. You may want to upgrade to the latest version or downgrade to an older version. There have been reports of bugs in GS 9.16 if I recall correctly. I think it is fixed in the current 9.18. To check, type in a terminal window or via PHP exec().

gs --version

P.S. I do not see gs or gslib listed in your delegates. So you may need to install it.
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr lzma openexr pangocairo png tiff wmf x xml zlib
Post Reply