Bug 695661

Summary: Ghostscript command hangs indefinitely
Product: Ghostscript Reporter: skom
Component: PDF InterpreterAssignee: Ken Sharp <ken.sharp>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P4    
Version: 9.15   
Hardware: PC   
OS: Windows 7   
Customer: Word Size: ---
Attachments: File to reproducing problem

Description skom 2014-11-01 16:00:10 UTC
Created attachment 11299 [details]
File to reproducing problem

Hello,

Trying to convert pdf to png/jpg


debug out
_______________


 » convert -debug All test.pdf test.png
2014-11-01T12:43:05+03:00 0:00.000 0.000u 6.8.9 Configure convert[8654]: utility.c/ExpandFilenames/945/Configure
  Command line: convert {-debug} {All} {test.pdf} {test.png}
2014-11-01T12:43:05+03:00 0:00.000 0.000u 6.8.9 Policy convert[8654]: policy.c/IsRightsAuthorized/574/Policy
  Domain: Path; rights=Read; pattern="test.pdf" ...
2014-11-01T12:43:05+03:00 0:00.000 0.000u 6.8.9 Blob convert[8654]: blob.c/OpenBlob/2598/Blob
    read 3 magic header bytes
2014-11-01T12:43:05+03:00 0:00.000 0.000u 6.8.9 Cache convert[8654]: cache.c/DestroyPixelCache/965/Cache
  destroy
2014-11-01T12:43:05+03:00 0:00.000 0.000u 6.8.9 Configure convert[8654]: configure.c/GetConfigureOptions/679/Configure
  Searching for configure file: "/usr/local/share/ImageMagick-6/magic.xml"
2014-11-01T12:43:05+03:00 0:00.000 0.000u 6.8.9 Configure convert[8654]: configure.c/GetConfigureOptions/679/Configure
  Searching for configure file: "/usr/local/lib/ImageMagick-6.8.9//config-Q16/magic.xml"
2014-11-01T12:43:05+03:00 0:00.000 0.000u 6.8.9 Configure convert[8654]: configure.c/GetConfigureOptions/679/Configure
  Searching for configure file: "/usr/local/etc/ImageMagick-6/magic.xml"
2014-11-01T12:43:05+03:00 0:00.000 0.000u 6.8.9 Configure convert[8654]: configure.c/GetConfigureOptions/679/Configure
  Searching for configure file: "/usr/local/share/doc/ImageMagick-6/magic.xml"
2014-11-01T12:43:05+03:00 0:00.000 0.000u 6.8.9 Configure convert[8654]: configure.c/GetConfigureOptions/679/Configure
  Searching for configure file: "/root/.config/ImageMagick/magic.xml"
2014-11-01T12:43:05+03:00 0:00.000 0.000u 6.8.9 Configure convert[8654]: configure.c/GetConfigureOptions/679/Configure
  Searching for configure file: "/root/.magick/magic.xml"
2014-11-01T12:43:05+03:00 0:00.000 0.000u 6.8.9 Configure convert[8654]: magic.c/LoadMagicCache/773/Configure
  Loading magic configure file "/usr/local/etc/ImageMagick-6/magic.xml" ...
2014-11-01T12:43:05+03:00 0:00.010 0.000u 6.8.9 Policy convert[8654]: policy.c/IsRightsAuthorized/574/Policy
  Domain: Coder; rights=Read; pattern="PDF" ...
2014-11-01T12:43:05+03:00 0:00.010 0.000u 6.8.9 Policy convert[8654]: policy.c/IsRightsAuthorized/574/Policy
  Domain: Path; rights=Read; pattern="test.pdf" ...
2014-11-01T12:43:05+03:00 0:00.010 0.000u 6.8.9 Blob convert[8654]: blob.c/OpenBlob/2598/Blob
    read 3 magic header bytes
2014-11-01T12:43:05+03:00 0:00.010 0.000u 6.8.9 Cache convert[8654]: cache.c/DestroyPixelCache/965/Cache
  destroy
2014-11-01T12:43:05+03:00 0:00.010 0.000u 6.8.9 Policy convert[8654]: policy.c/IsRightsAuthorized/574/Policy
  Domain: Path; rights=Read; pattern="test.pdf" ...
2014-11-01T12:43:05+03:00 0:00.010 0.000u 6.8.9 Blob convert[8654]: blob.c/OpenBlob/2598/Blob
    read 3 magic header bytes
2014-11-01T12:43:05+03:00 0:00.010 0.000u 6.8.9 Resource convert[8654]: resource.c/AcquireUniqueFileResource/468/Resource
  ...
2014-11-01T12:43:05+03:00 0:00.010 0.000u 6.8.9 Resource convert[8654]: resource.c/AcquireUniqueFileResource/509/Resource
  Acquire /tmp/magick-8654AU3wt3V2GlaY
2014-11-01T12:43:05+03:00 0:00.010 0.000u 6.8.9 Resource convert[8654]: resource.c/RelinquishUniqueFileResource/895/Resource
  Relinquish /tmp/magick-8654AU3wt3V2GlaY
2014-11-01T12:43:05+03:00 0:00.140 0.130u 6.8.9 Resource convert[8654]: resource.c/AcquireUniqueFileResource/468/Resource
  ...
2014-11-01T12:43:05+03:00 0:00.140 0.130u 6.8.9 Resource convert[8654]: resource.c/AcquireUniqueFileResource/509/Resource
  Acquire /tmp/magick-8654fBxxztn6A3Qt
2014-11-01T12:43:05+03:00 0:00.140 0.130u 6.8.9 Configure convert[8654]: configure.c/GetConfigureOptions/679/Configure
  Searching for configure file: "/usr/local/share/ImageMagick-6/delegates.xml"
2014-11-01T12:43:05+03:00 0:00.140 0.130u 6.8.9 Configure convert[8654]: configure.c/GetConfigureOptions/679/Configure
  Searching for configure file: "/usr/local/lib/ImageMagick-6.8.9//config-Q16/delegates.xml"
2014-11-01T12:43:05+03:00 0:00.140 0.130u 6.8.9 Configure convert[8654]: configure.c/GetConfigureOptions/679/Configure
  Searching for configure file: "/usr/local/etc/ImageMagick-6/delegates.xml"
2014-11-01T12:43:05+03:00 0:00.140 0.130u 6.8.9 Configure convert[8654]: configure.c/GetConfigureOptions/679/Configure
  Searching for configure file: "/usr/local/share/doc/ImageMagick-6/delegates.xml"
2014-11-01T12:43:05+03:00 0:00.140 0.130u 6.8.9 Configure convert[8654]: configure.c/GetConfigureOptions/679/Configure
  Searching for configure file: "/root/.config/ImageMagick/delegates.xml"
2014-11-01T12:43:05+03:00 0:00.140 0.130u 6.8.9 Configure convert[8654]: configure.c/GetConfigureOptions/679/Configure
  Searching for configure file: "/root/.magick/delegates.xml"
2014-11-01T12:43:05+03:00 0:00.140 0.130u 6.8.9 Configure convert[8654]: delegate.c/LoadDelegateCache/1475/Configure
  Loading delegate configuration file "/usr/local/etc/ImageMagick-6/delegates.xml" ...
2014-11-01T12:43:05+03:00 0:00.140 0.130u 6.8.9 Resource convert[8654]: resource.c/AcquireUniqueFileResource/468/Resource
  ...
2014-11-01T12:43:05+03:00 0:00.140 0.130u 6.8.9 Resource convert[8654]: resource.c/AcquireUniqueFileResource/509/Resource
  Acquire /tmp/magick-8654ugv-THLFzUxZ
2014-11-01T12:43:05+03:00 0:00.140 0.130u 6.8.9 Resource convert[8654]: resource.c/RelinquishUniqueFileResource/895/Resource
  Relinquish /tmp/magick-8654ugv-THLFzUxZ
2014-11-01T12:43:05+03:00 0:00.140 0.130u 6.8.9 Policy convert[8654]: policy.c/IsRightsAuthorized/574/Policy
  Domain: Delegate; rights=Execute; pattern="gs" ...
   **** Unknown operator: '70.761.396137.516' looks like a malformed number, replacing with 0.
   **** Unknown operator: '334..6' looks like a malformed number, replacing with 0.
   **** Unknown operator: '322.822.32' looks like a malformed number, replacing with 0.
   **** Unknown operator: '523.676365.832' looks like a malformed number, replacing with 0.
   **** Unknown operator: '70.761.396137.516' looks like a malformed number, replacing with 0.
   **** Unknown operator: '334..6' looks like a malformed number, replacing with 0.
   **** Unknown operator: '322.822.32' looks like a malformed number, replacing with 0.
   **** Unknown operator: '523.676365.832' looks like a malformed number, replacing with 0.
   **** Unknown operator: '57.807955.34..6.8296' looks like a malformed number, replacing with 0.
   **** Unknown operator: '32634..6.77816' looks like a malformed number, replacing with 0.
   **** Unknown operator: '3161.34..6.7.791' looks like a malformed number, replacing with 0.
   **** Unknown operator: '57562.6.791' looks like a malformed number, replacing with 0.
   **** Unknown operator: '70.76.2156131791' looks like a malformed number, replacing with 0.
   **** Unknown operator: '57562.6.791' looks like a malformed number, replacing with 0.
   **** Unknown operator: '321334..41.102' looks like a malformed number, replacing with 0.
   **** Unknown operator: '.416.80' looks like a malformed number, replacing with 0.
   **** Unknown operator: '32.041..6.024' looks like a malformed number, replacing with 0.
   **** Unknown operator: '3231511..6.071' looks like a malformed number, replacing with 0.
   **** Unknown operator: '.6.138' looks like a malformed number, replacing with 0.
   **** Unknown operator: '31..032' looks like a malformed number, replacing with 0.
   **** Unknown operator: '31..061' looks like a malformed number, replacing with 0.
   **** Unknown operator: '70.76.32' looks like a malformed number, replacing with 0.
   **** Unknown operator: '8222.21562.57791' looks like a malformed number, replacing with 0.
   **** Unknown operator: '31.2.21562.57795606621562.3032556.555' looks like a malformed number, replacing with 0.
   **** Unknown operator: '91..754' looks like a malformed number, replacing with 0.
   **** Unknown operator: '59.793222.0633' looks like a malformed number, replacing with 0.
   **** Unknown operator: '7267.89322.484' looks like a malformed number, replacing with 0.
   **** Unknown operator: '702.159322320.8702.1591' looks like a malformed number, replacing with 0.
   **** Unknown operator: '66.8439322.484' looks like a malformed number, replacing with 0.
   **** Unknown operator: '66.7159322320.866.71596' looks like a malformed number, replacing with 0.
   **** Unknown operator: '67.7.9' looks like a malformed number, replacing with 0.
   **** Unknown operator: '3971923..196' looks like a malformed number, replacing with 0.
   **** Unknown operator: '7222.3132323.196' looks like a malformed number, replacing with 0.
   **** Unknown operator: '23..196' looks like a malformed number, replacing with 0.
   **** Unknown operator: '361.323.3465' looks like a malformed number, replacing with 0.
   **** Unknown operator: '361.332323.0' looks like a malformed number, replacing with 0.
   **** Unknown operator: '361.323.6314' looks like a malformed number, replacing with 0.
   **** Unknown operator: '23..196' looks like a malformed number, replacing with 0.
   **** Unknown operator: '68.62132323.196' looks like a malformed number, replacing with 0.
   **** Unknown operator: '5018923..196' looks like a malformed number, replacing with 0.
   **** Unknown operator: '70..7545' looks like a malformed number, replacing with 0.
   **** Unknown operator: '70..7544' looks like a malformed number, replacing with 0.
   **** Unknown operator: '70..7545' looks like a malformed number, replacing with 0.
   **** Unknown operator: '702320.7.196956195' looks like a malformed number, replacing with 0.
   **** Unknown operator: '693042.7.196956195' looks like a malformed number, replacing with 0.
   **** Unknown operator: '.353042.1' looks like a malformed number, replacing with 0.
   **** Unknown operator: '.353042.1' looks like a malformed number, replacing with 0.
   **** Unknown operator: '54102936.4824353196436.465435319144' looks like a malformed number, replacing with 0.
   **** Unknown operator: '36644343531849456.41343531801456.3734353176564' looks like a malformed number, replacing with 0.
   **** Unknown operator: '66232493531841456.15993531841456.189353184564' looks like a malformed number, replacing with 0.
   **** Unknown operator: '3486221353765934861914353819.34861497.353874' looks like a malformed number, replacing with 0.
   **** Unknown operator: '353479.34739.696565324347691345536159347688744' looks like a malformed number, replacing with 0.
   **** Unknown operator: '353699.3473861435376934768.696568019347681294' looks like a malformed number, replacing with 0.
   **** Unknown operator: '4766794553929.34736334553929.347357894' looks like a malformed number, replacing with 0.
   **** Unknown operator: '583.79.347318291' looks like a malformed number, replacing with 0.

------------------------------------------------------------


out of "top" indefinitely after previous command

15209 root      20   0 1030176 966340   6204 R  99.3  0.4   1:02.67 gs -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 -sDEVICE=pam -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r72x72 -dUseCIEColor -sOutputFile=/tmp/magick-15207mI_npATUgwSg%d -f/tmp/magick-15207TUPZw3q7ze04 -f/tmp/magick-15207o-msKazvN47S



-------------------------------------------------------------


environment

# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:        14.04
Codename:       trusty
__________________________________________________

 » convert --version
Version: ImageMagick 6.8.9-9 Q16 x86_64 2014-10-31 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC OpenMP
Delegates: bzlib fontconfig freetype jng jpeg pangocairo png x xml zlib

__________________________________________________

» gs -v
GPL Ghostscript 9.15 (2014-09-22)
Copyright (C) 2014 Artifex Software, Inc.  All rights reserved.

__________________________________________________

 » convert -list resource 
  File       Area     Memory        Map       Disk   Thread  Throttle       Time
--------------------------------------------------------------------------------
   768   540.92GB  251.89GiB  503.77GiB  unlimited       32         0  unlimited



----------------------------------------------------------------------------

file to reproducing in attachment
I think this file is bugged, but I'd like to got finish convert or stop converting it anyway with some explained errors out to stdout.
------------------------------------------------------------------------

ImageMagick team forward me to this bug report :)

Original thread on IM forum - http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=26479&sid=0f878f27b9eda298fbeefe179e39340b



------------------------------------------------------------------------




Thank you.
Comment 1 Chris Liddell (chrisl) 2014-11-02 01:14:13 UTC
We *do* emit warnings, which you have, in fact, copied into your bug report, several along the lines of:
**** Unknown operator: '321334..41.102' looks like a malformed number, replacing with 0.

That is clearly not a well formed number, and indicate a very broken PDF file. If IM is not allowing those to be seen under normal conditions, that's hardly our problem!

In truth, I'm not sure if there's much we can do, we end up with some extremely large coordinates, but they *are* valid - and hanling that takes time.

One of us will look into this in more details at some point.
Comment 2 Ken Sharp 2014-11-02 03:42:05 UTC
The file is badly broken. Several of the content streams have Flat errors which leads (I think) to the corrupted co-ordinates.

In any event, this obviously is *not* a problem with the build process!

I'll see if we can detect the flate errors.
Comment 3 skom 2014-11-03 02:15:03 UTC
Thank you very much
Comment 4 Ken Sharp 2014-11-03 07:52:29 UTC
Well, we cannot use the zlib error, as we know from prior experience (see Bug #688716) that Acrobat ignores such errors.

The problem seems to be that we end up with some truly enormous co-ordinates, as a result of the corruption in the PDF file, and the time is taken by GS trying to subdivide a curve into line segments, where the curve extends to a very extreme point. I don't think it has hung, but it may take an unrealistically long time to terminate.

We can't use the large co-ordinate as an error as co-ordinates are real numbers in PDF and can vary to +/- 3.403 x 10^38, also in this case the large co-ordinates are less than the maximum fixed precision values in Ghostscript, so we can't catch an attempt to write outside the maximum area and abort.

So the only realistic solution I can come up with is to have corrupted files throw an error (if -dPDFSTOPONERROR is set) instead of trying to recover.

Commit b2a6decb294ca8c48c71da2211f3284b2334d921 implements that change.