Bug 702381 - ghostscript hangs at 100% cpu when converting this pdf to png
Summary: ghostscript hangs at 100% cpu when converting this pdf to png
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: PDF Interpreter (show other bugs)
Version: 9.52
Hardware: PC All
: P4 major
Assignee: Ray Johnston
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-07 21:30 UTC by David Jameson
Modified: 2021-05-04 23:18 UTC (History)
3 users (show)

See Also:
Customer:
Word Size: ---


Attachments
test pdf file which causes hang (155.24 KB, application/pdf)
2020-05-07 21:30 UTC, David Jameson
Details
Simplified sample file (5.17 KB, application/pdf)
2020-06-23 06:23 UTC, Peter Cherepanov
Details
Patch (1.29 KB, patch)
2020-06-23 07:17 UTC, Peter Cherepanov
Details | Diff
New patch (1.75 KB, patch)
2020-11-11 08:53 UTC, Peter Cherepanov
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Jameson 2020-05-07 21:30:11 UTC
Created attachment 19194 [details]
test pdf file which causes hang

When converting this file from pdf to png, gs hangs forever at 100% cpu. Same behaviour with v9.50 and 9.52. Works ok with version 9.25.

To recreate:

magick -verbose test2.pdf test2.png

Here is the gs command being executed:

'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pamcmyk32' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72' -dUseCIEColor  '-sOutputFile=/tmp/magick-66024HqXrRKvz2u4%d' '-f/tmp/magick-6602wAEeyPyqRg96' '-f/tmp/magick-66022lIqEaMvwCN9'
Comment 1 Ray Johnston 2020-05-08 17:06:39 UTC
There are TWO input files processed by the given command line:
'-f/tmp/magick-6602wAEeyPyqRg96' '-f/tmp/magick-66022lIqEaMvwCN9'

I am able to duplicate the problem with the attached file, however.
Comment 2 David Jameson 2020-05-09 18:06:04 UTC
Not sure what ImageMagick does internally. To test I'm just running "magick test2.pdf test2.png", and that gs command is what magick is running.

When I upload the file to a pdf validator it shows lots of missing objects. It was originally converted from Adobe InDesign to pdf by PhotoShop as a Linearized
pdf, then edited and saved a few times, so I suspect it got corrupted
somewhere along the line.

The problem is that the older versions of gs seem to handle it fine, it's just the recent versions that hang.
Comment 3 Peter Cherepanov 2020-06-23 06:23:34 UTC
Created attachment 19369 [details]
Simplified sample file

The loop is caused by a circular /ParentResources attribute.
This branch of code is triggered by an error in the sample file: misplaced /Form resources in a Type 3 font. This font has /Resource dictionaries added to /CharProcs entries rather than the font dictionary.

This simplified sample file keeps the malformed Type 3 font but disposes of everything else.
Comment 5 Ray Johnston 2020-06-23 14:29:21 UTC
I'll review the patch, but examining this shows there are issues with
where the Resource is supposed to come from.
Comment 6 Jeroen Bobbeldijk 2020-08-17 16:27:12 UTC
Any update on this? I'm also having this issue.
I'm willing to test patches.

The patch from #4 seems to fix the issue for me.
Comment 8 Ere Maijala 2020-12-09 13:48:47 UTC
The pdf (https://digi.kansalliskirjasto.fi/sanomalehti/binding/423358/pdf/Keski_Suomi_23_06_06_1874.pdf) downloaded from page:

https://digi.kansalliskirjasto.fi/sanomalehti/binding/423358?page=1&set_language=en 

is exhibiting the same 100% CPU behavior with the following command:

gs -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r150 -dFirstPage=1 -dLastPage=1 -sDEVICE=jpeg -o test.jpg Keski_Suomi_23_06_06_1874.pdf

Is this maybe the same issue or should I file another one?
Comment 9 Peter Cherepanov 2020-12-10 01:37:12 UTC
The sample file from the comment #8 demonstrates a unrelated problem. It is something that loops around .addbfrange . Please open a separate bug report.
Comment 10 Peter Cherepanov 2020-12-10 04:16:42 UTC
Ere Maijala, I opened a new bug 703246 to track this issue.
I also submitted a proposed patch that solves it.
Comment 11 Ere Maijala 2020-12-10 07:05:54 UTC
(In reply to Peter Cherepanov from comment #10)
> Ere Maijala, I opened a new bug 703246 to track this issue.
> I also submitted a proposed patch that solves it.

Thank you!
Comment 12 Ray Johnston 2021-05-04 23:18:09 UTC
Fixed in commit ec2699f50aa3ada4ef2c477c7577331a3950bcc8, but this does not
resolve the CharProc lookup. Commit 2aaa240515d77b486adfd9d217c32d3cad7683f5
is needed to fix the rendering, preventing the multiple instances of the logo
along the right side.