Bug 693591 - Infinite loop writing pdf file
Summary: Infinite loop writing pdf file
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: PDF Writer (show other bugs)
Version: master
Hardware: PC All
: P4 normal
Assignee: Ken Sharp
URL:
Keywords:
: 694531 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-01-28 04:00 UTC by Marcos H. Woehrmann
Modified: 2013-08-22 05:36 UTC (History)
1 user (show)

See Also:
Customer:
Word Size: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marcos H. Woehrmann 2013-01-28 04:00:32 UTC
The following command line locks up:

  bin/gs -o test.pdf -sDEVICE=pdfwrite ./Bug693422.pdf
Comment 1 Marcos H. Woehrmann 2013-01-28 04:02:04 UTC
Possibly relevant gdb output:

(gdb) where
#0  refs_clear_marks (cmem=0x102022c58, vptr=0x10308aba8, size=400, pstype=0x10123a520) at igcref.c:118
#1  0x000000010018ddb2 in gc_objects_clear_marks (mem=0x102022c58, cp=0x1019472f0) at igc.c:622
#2  0x000000010018c10c in gs_gc_reclaim (pspaces=0x102071f78, global=1) at igc.c:266
#3  0x00000001002ca05c in context_reclaim (pspaces=0x102071f78, global=1) at zcontext.c:280
#4  0x000000010012721c in gs_vmreclaim (dmem=0x102071f70, global=1) at ireclaim.c:155
#5  0x0000000100126f14 in ireclaim (dmem=0x102071f70, space=-1) at ireclaim.c:77
#6  0x000000010011cbf0 in interp_reclaim (pi_ctx_p=0x10190cc18, space=-1) at interp.c:432
#7  0x0000000100122370 in interp (pi_ctx_p=0x10190cc18, pref=0x7fff5fbfeac8, perror_object=0x7fff5fbfed60) at interp.c:1704
#8  0x000000010011cf14 in gs_call_interp (pi_ctx_p=0x10190cc18, pref=0x7fff5fbfec38, user_errors=1, pexit_code=0x7fff5fbfed70, perror_object=0x7fff5fbfed60) at interp.c:501
#9  0x000000010011cccc in gs_interpret (pi_ctx_p=0x10190cc18, pref=0x7fff5fbfec38, user_errors=1, pexit_code=0x7fff5fbfed70, perror_object=0x7fff5fbfed60) at interp.c:459
#10 0x000000010010ade9 in gs_main_interpret (minst=0x10190cb80, pref=0x7fff5fbfec38, user_errors=1, pexit_code=0x7fff5fbfed70, perror_object=0x7fff5fbfed60) at imain.c:235
#11 0x000000010010c21f in gs_main_run_string_end (minst=0x10190cb80, user_errors=1, pexit_code=0x7fff5fbfed70, perror_object=0x7fff5fbfed60) at imain.c:609
#12 0x000000010010c041 in gs_main_run_string_with_length (minst=0x10190cb80, str=0x101917510 "<2e2f4275673639333432322e706466>.runfile", length=40, user_errors=1, pexit_code=0x7fff5fbfed70, perror_object=0x7fff5fbfed60) at imain.c:567
#13 0x000000010010bf56 in gs_main_run_string (minst=0x10190cb80, str=0x101917510 "<2e2f4275673639333432322e706466>.runfile", user_errors=1, pexit_code=0x7fff5fbfed70, perror_object=0x7fff5fbfed60) at imain.c:549
#14 0x0000000100110747 in run_string (minst=0x10190cb80, str=0x101917510 "<2e2f4275673639333432322e706466>.runfile", options=3) at imainarg.c:866
#15 0x0000000100110602 in runarg (minst=0x10190cb80, pre=0x1007f76d0 "", arg=0x7fff5fbffb3c "./Bug693422.pdf", post=0x1007ed9da ".runfile", options=3) at imainarg.c:855
#16 0x000000010011013f in argproc (minst=0x10190cb80, arg=0x7fff5fbffb3c "./Bug693422.pdf") at imainarg.c:788
#17 0x000000010010df86 in gs_main_init_with_args (minst=0x10190cb80, argc=5, argv=0x7fff5fbff940) at imainarg.c:226
#18 0x0000000100001832 in main (argc=5, argv=0x7fff5fbff940) at gs.c:96
(gdb)
Comment 2 Marcos H. Woehrmann 2013-01-28 04:28:42 UTC
Neither valgrind nor memento had any interesting to say about the problem.
Comment 3 Ken Sharp 2013-01-28 09:36:23 UTC
I don't think it has actually entered an infinte loop, its just very slow.

The problem is that its yet another insane Cairo file, and it nests deeper than our graphics state stack, with the result that we throw errors. So even if you left it long enough to complete, the output would be incorrect.

Ps2write, which collapses all the transparency into images, works fine with this file.

We've seen this before with Cairo files, and the only proper solution is to make our graphics state stack dynamic instead of static. However that's a fairly big task (a simplistic hack fell apart very quickly) involving garbage collection, so I'm leaving this open to remind me to do that work.
Comment 4 Marcos H. Woehrmann 2013-02-11 22:17:50 UTC
This command also generates a metric boat load of warnings:

   **** Error reading a content stream. The page may be incomplete.
   **** Error reading a content stream. The page may be incomplete.
   **** Warning: Form stream has unbalanced q/Q operators (too many q's)
   **** Error reading a content stream. The page may be incomplete.
   **** Error reading a content stream. The page may be incomplete.
   **** Warning: Form stream has unbalanced q/Q operators (too many q's)
   **** Error reading a content stream. The page may be incomplete.
   **** Error reading a content stream. The page may be incomplete.
   **** Warning: Form stream has unbalanced q/Q operators (too many q's)
   **** Error reading a content stream. The page may be incomplete.
...
Comment 5 Ken Sharp 2013-02-12 07:55:36 UTC
(In reply to comment #4)
> This command also generates a metric boat load of warnings:
> 
>    **** Error reading a content stream. The page may be incomplete.
>    **** Error reading a content stream. The page may be incomplete.
>    **** Warning: Form stream has unbalanced q/Q operators (too many q's)

pdfwrite is returning an error, but the PDF interpreter is configured to ignore these errors and continue by default. This aborts the current stream.

See comment #3 for a brief explanation of the problem. Because of the way this file is constructed (ugly slow and horrible) this causes a lot of these warnings.

Use -dPDFSTOPONERROR and you'll get a simple error instead.
Comment 6 Ken Sharp 2013-08-22 05:00:31 UTC
*** Bug 694531 has been marked as a duplicate of this bug. ***
Comment 7 Ken Sharp 2013-08-22 05:36:33 UTC
Fixed in commit dfd7fc9fe152245256e437141dd7780c8313c971