Bug 697221 - Process hangs on PDF to JPG conversion
Summary: Process hangs on PDF to JPG conversion
Status: RESOLVED INVALID
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: General (show other bugs)
Version: 9.20
Hardware: PC Windows 10
: P4 normal
Assignee: Default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-19 00:32 UTC by 1.44mb
Modified: 2016-10-19 01:03 UTC (History)
0 users

See Also:
Customer:
Word Size: 64


Attachments
Local newspaper source (3.15 MB, application/pdf)
2016-10-19 00:32 UTC, 1.44mb
Details

Note You need to log in before you can comment on or make changes to this bug.
Description 1.44mb 2016-10-19 00:32:32 UTC
Created attachment 13026 [details]
Local newspaper source

When converting PDF to JPG, GhostScript process hangs on certain PDFs.
There is something wrong with the PDF i assume, although it is displayed correctly on Chrome or other PDF viewers.

Here is the command i run;
"c:\Program Files\gs\gs9.20\bin\gswin64c.exe" -dNOPAUSE -dDEBUG -sDEVICE=jpeg -r144 -sOutputFile=p%03d.jpg test.pdf

1. What can i do to gracefully exit the process if it can't convert a page in 1 minute (timeout parameter)?

2. What is the source of this problem? Is the PDF corrupt? (If yes, why is it displayed correctly on PDF viewers) Is it a bug in GS?
Comment 1 Ken Sharp 2016-10-19 01:03:05 UTC
(In reply to 1.44mb from comment #0)

> 1. What can i do to gracefully exit the process if it can't convert a page
> in 1 minute (timeout parameter)?

Well, you could write your own code around the Ghostscript interpreter and library. Since the interpreter hasn't actually hung it will call back to the parent application at regular intervals and a watchdog timer in the parent would enable you to close the application.

 
> 2. What is the source of this problem? Is the PDF corrupt? (If yes, why is
> it displayed correctly on PDF viewers) Is it a bug in GS?

If I attempt to open the attached PDF file with Acrobat it tells me "A drawing error occurred" which is a pretty good indication that your PDF file is broken. Badly broken in fact, since Acrobat habitually opens all sorts of corrupted and damaged PDF files.

The problem seems to exist because of an image mask which is painted using a Pattern which itself uses an image and the pattern has a crazy Matrix: 

/Matrix[1.20756 0 45595027918153.2 1.20756 211.9743 1212.9919]

which looks like an uninitialised number in index 3 to me, I very strongly suspect that massive number should be a zero. If I correct that Matrix to something sensible (eg 0) then the file runs to completion. Note that there are two occurrences of this crazy value.

I doubt Ghostscript has actually hung, its valiantly painting a monstrously large pattern billions of times to satisfy the request.

The PDF file claims to have been created by PDFSharp 1.50.4000, I'd suggest you take the problem up with them.