Bug 703265 - Ghostscript hangs forever while extracting images from pdf
Summary: Ghostscript hangs forever while extracting images from pdf
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: General (show other bugs)
Version: 9.53.3
Hardware: PC Windows 10
: P4 major
Assignee: Robin Watts
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-11 13:53 UTC by Alexander
Modified: 2021-02-26 01:59 UTC (History)
1 user (show)

See Also:
Customer:
Word Size: ---


Attachments
the test pdf file that causes Ghostscript to hang (767.32 KB, application/pdf)
2020-12-11 13:53 UTC, Alexander
Details
Simplified sample file (2.34 KB, application/pdf)
2020-12-11 23:23 UTC, Peter Cherepanov
Details
Experimental patch (1.53 KB, patch)
2020-12-12 09:04 UTC, Peter Cherepanov
Details | Diff
Patch (4.78 KB, patch)
2020-12-13 06:06 UTC, Peter Cherepanov
Details | Diff
703265.patch (19.20 KB, patch)
2021-02-26 01:59 UTC, Ray Johnston
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander 2020-12-11 13:53:06 UTC
Created attachment 20354 [details]
the test pdf file that causes Ghostscript to hang

The following command to extract images form the test file (in attachment):

gs9.53.3\bin\gswin64c.exe -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dUseCropBox -dAlignToPixels=0 -dGridFitTT=2 -sDEVICE=png16m -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dPDFFitPage  -dFirstPage=1 -dLastPage=3 -dDEVICEWIDTH=860 -dDEVICEHEIGHT=1113   -sOutputFile=c:\Temp\test\test-%d.png c:\Temp\test\test.pdf


hangs forever (tried to wait more than 12 hours) :

GPL Ghostscript 9.53.3 (2020-10-01)
Copyright (C) 2020 Artifex Software, Inc.  All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
Processing pages 1 through 3.
Page 1
Page 2


the test file is a part of big file that also could not be processed by Ghostscript
Comment 1 Peter Cherepanov 2020-12-11 23:23:49 UTC
Created attachment 20355 [details]
Simplified sample file

This is a regression; v.9.50 works fine, v.9.51 and higher fail.
The simplest command line is: gs FOO.pdf
The bug is related on overprint, tiled patterns, and smooth shading used together.
Comment 3 Ray Johnston 2020-12-11 23:54:42 UTC
Based on Peter's evaluation, assigning to Michael -- He's been VERY active in
this area in the not too distance past.

Changing to UNCONFIRMED until Michael can validate the issue.
Comment 4 Peter Cherepanov 2020-12-12 09:04:46 UTC
Created attachment 20356 [details]
Experimental patch

Bisection shows that this bug was introduced by the commit 55a7a41998f35ae23aedf2fdb83698dde1453d58 . Effectively undoing it restores normal operation of the current development version.
Comment 5 Michael Vrhel 2020-12-12 19:55:06 UTC
Passing to Robin based upon the bisect results
Comment 6 Michael Vrhel 2020-12-12 19:55:15 UTC
Passing to Robin based upon the bisect results
Comment 8 Robin Watts 2021-01-16 00:54:08 UTC
This patch breaks page 14 of  tests_private/xl/pcl6cet3.0/C305.bin.pbmraw.600.1..pcl

And page 17 of 
tests_private/xl/pcl6cet3.0/C421.bin.pbmraw.600.1..pcl

And page 10 of
tests_private/xl/pcl6cet3.0/C422.bin.pbmraw.600.1..pcl

And pages 7 and 9 of
tests_private/xl/pcl6cet3.0/C603.bin.pbmraw.600.1..pcl

And page 24 of
tests_private/xl/pcl6cet/c329.bin.pbmraw.600.1..pcl

And page 1 of
tests_private/xps/xpsfts-a4/fts_33xx.xps.bitrgbtags.300.1..xps
tests_private/xps/xpsfts-a4/fts_33xx.xps.pbmraw.72.0..xps

And page 2 of
tests_private/xps/xpsfts-a4/fts_34xx.xps.bitrgbtags.300.1..xps
tests_private/xps/xpsfts-a4/fts_34xx.xps.ppmraw.72.0..xps

The rest of the diffs look good though.
Comment 9 Robin Watts 2021-02-19 19:19:34 UTC
Going back to first principles here, and reproducing the initial problem in a debug build (actually a memento build), with 9.53.3 I see we get an infinite number(*) of "No encode_color proc defined for device." errors.

(*May not actually be infinite).

This doesn't happen with the latest code, so it looks like it has been fixed since. We do get a SEGV with the latest version to do with gdev_prn_close attempting to access through a NULL ppdev->bg_print, but with the trivial fix for that it's fine.

I will investigate some more.
Comment 10 Ray Johnston 2021-02-21 00:35:52 UTC
This occurs because of the pattern-clist playback. A simple Windows command
line is:
   -dFirstPage=1 -dLastPage=1 j6.pdf

The end of pattern-clist playback is what closes the flp device.
Comment 11 Ray Johnston 2021-02-23 17:06:16 UTC
Back to Robin who is re-working the compositor interface.

I had determined it was due to the pattern_clist playback being confused into
switching devices because of an overprint compositor action (when there was a
'clipper' forwarding device installed).

This needed some analysis, and a change to the return information from the
create_compositor device proc.
Comment 12 Robin Watts 2021-02-25 12:54:18 UTC
Fixed with:

commit a754bd375a625368567947b1e1b77ce3e5c06a3f
Author: Robin Watts <Robin.Watts@artifex.com>
Date:   Mon Feb 22 19:57:35 2021 +0000

    Bug 703265: Tweak create_compositor device method.

    Update create_compositor device method, so that it always returns
    the compositor device (or the leaf device if there is no specific
    compositor device). The device now returns 1 if we created a
    compositor device to wrap the given device.

    This should enable us to identify exactly the cases where forwarding
    devices need to update which device they forward to.

    In particular, this allows us to remove the horribly fragile code
    in apply_create_compositor in gxclrast.c, and to ensure that we
    correctly identify the 'new compositor' case.

    This avoids us sending stuff to the wrong device, and having to
    cope with a slew of warnings.
Comment 13 Ray Johnston 2021-02-26 01:59:52 UTC
Created attachment 20666 [details]
703265.patch

This is the real patch. The one from Peter simply masks the problem because it
alters the clip path.