Bug 694353 - **** File has unbalanced q/Q operators (too many Q's) **** endless loop
Summary: **** File has unbalanced q/Q operators (too many Q's) **** endless loop
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: PDF Interpreter (show other bugs)
Version: master
Hardware: PC Windows 8
: P4 normal
Assignee: Ken Sharp
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-17 14:51 UTC by Stanislav Kuzmin
Modified: 2013-06-19 11:23 UTC (History)
1 user (show)

See Also:
Customer:
Word Size: ---


Attachments
sample file (151.88 KB, application/pdf)
2013-06-17 14:52 UTC, Stanislav Kuzmin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stanislav Kuzmin 2013-06-17 14:51:37 UTC
Last current ghostscript git build (9.08) falls in endless error message loop with message **** File has unbalanced q/Q operators (too many Q's) ****
See sample file in attachment.
Command line sample: gswin32 -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -dGraphicsAlphaBits=4 -sOutputFile=test.png comp.pdf
Comment 1 Stanislav Kuzmin 2013-06-17 14:52:13 UTC
Created attachment 9988 [details]
sample file
Comment 2 Stanislav Kuzmin 2013-06-18 13:59:34 UTC
It seems that the problem with image object stream parsing. Object name: /I7, reference: [4 0]. I ran script with PDFSTOPONERROR and PDFDEBUG and significant part of output is:
.................................
q
129.780701 0 0 42.088 18.0 706.116699 cm
/I7 Do
%Resolving: [4 0]
Error: /rangecheck in --.execform1--
Operand stack:
   --dict:6/15(L)--   --nostringval--   --nostringval--   --nostringval--   --nostringval--   --nostringval--   --nostringval--   false   --dict:12/20(L)--   --nostringval--   --nostringval--   DCTDecode   --nostringval--   0
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1932   1   3   %oparray_pop   1931   1   3   %oparray_pop   1915   1   3   %oparray_pop   --nostringval--   --nostringval--   2   1   1   --nostringval--   %for_pos_int_continue   --nostringval--   --nostringval--   --nostringval--   --nostringval--   %array_continue   --nostringval--   --nostringval--   %loop_continue   --nostringval--   154467   --nostringval--   10   1   1874   6   11   %oparray_pop   --nostringval--   false   1   %stopped_push   1873   6   11   %oparray_pop   --nostringval--   (gstatetype)   --dict:0/0(L)--   --nostringval--   --nostringval--   %loop_continue   --nostringval--   153338   --nostringval--   --nostringval--   --nostringval--   --nostringval--   --nostringval--   --nostringval--   %array_continue   --nostringval--   --nostringval--
Dictionary stack:
   --dict:1176/1684(ro)(G)--   --dict:1/20(G)--   --dict:82/200(L)--   --dict:82/200(L)--   --dict:109/127(ro)(G)--   --dict:293/300(ro)(G)--   --dict:27/32(L)--   --dict:6/8(L)--   --dict:24/40(L)--   --dict:1/1(ro)(G)--   --dict:2/5(L)--   --dict:1/1(ro)(G)--   --dict:7/18(L)--
Current allocation mode is local
Last OS error: No such file or directory

Any suggestions please?
Comment 3 Ken Sharp 2013-06-18 15:23:05 UTC
The basic problem is that your PDF file is broken. If you open it in Acrobat it also gives you an error. Until someone has the time to look at this, the only suggestion is to fix your PDF file.

Note that I7 appears to be a DCT encoded image (JPEG), possibly there is something wrong with that data.
Comment 4 Stanislav Kuzmin 2013-06-18 18:48:45 UTC
But this file successfully opens with Acrobat, mupdf and Chrome internal viewer for example. And, yes, I7 - encoded image stream object and it was successfully viewed with that programs. PDF producer of this file obviously is not good, but I can not affect for it quality.
Comment 5 Ken Sharp 2013-06-18 19:58:52 UTC
(In reply to comment #4)
> But this file successfully opens with Acrobat, mupdf and Chrome internal
> viewer for example.

Acrobat gives me an error when I open the file, MuPDF opens it mostly blank (on my version which is a bit old).

I am  not saying its not being addressed, but I have a long list of bugs to look at.
Comment 6 Ken Sharp 2013-06-19 10:36:16 UTC
As anticipated, the PDF file is invalid. The image stream uses 2 filters
([/ASCII85Decode/DCTDecode]) *and* supplies a DecodeParams array ([<<>>]).

The DecodeParams array is nonsense, since it has no parameters, and also invalid,
the two arrays must have the same number of entries (or DecodeParams can be elided). If they are different we don't know which Params apply to which Filter.

commit daceba62fcce274fc62e750ac186b3a9026554ad works around this broken file by
testing the lengths of the 2 arrays and ignoring the DecodeParams if the two lengths differ. (we also emit a warning).
Comment 7 Stanislav Kuzmin 2013-06-19 11:23:53 UTC
Thank you very much! Works perfectly.