Bug 695848 - Ghostscript decode error when opening PDF
Summary: Ghostscript decode error when opening PDF
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: PDF Interpreter (show other bugs)
Version: 9.15
Hardware: PC Windows 7
: P4 normal
Assignee: Ken Sharp
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-23 02:23 UTC by gunst.pieter
Modified: 2015-02-23 04:38 UTC (History)
0 users

See Also:
Customer:
Word Size: ---


Attachments
The PDF that fails to open. (2.19 MB, application/pdf)
2015-02-23 02:23 UTC, gunst.pieter
Details

Note You need to log in before you can comment on or make changes to this bug.
Description gunst.pieter 2015-02-23 02:23:36 UTC
Created attachment 11485 [details]
The PDF that fails to open.

Hey,

I have this PDF that fails to open with Ghostscript. I have tried several PDF analysis tools but none have reported that the PDF contains errors or is broken in any way. I did not create the PDF so I don't know how it was made. The PDF:

http://bit.ly/1Ed4vvT

If I open it for example with IrfanView I get the following error:

http://bit.ly/1FNXcfY

"Ghostscript decode error. This file can't be loaded/decoded."

When trying to convert the PDF to PNG with nconvert using Ghostscript I get:


>nconvert.exe -dpi 300 -out png -merge_alpha -o out.png -xall odd_numbers.pdf

** NCONVERT v6.70 (c) 1991-2015 Pierre-E Gougelet (Feb 18 2015/16:46:22) **
        Version for Windows Xp/Vista/7 x64  (All rights reserved)
** This is freeware software (for non-commercial use)

GS: (C:\Program Files\gs\gs9.15\bin\gsdll64.dll)
ARG 0 -dNODISPLAY
ARG 1 -dQUIET
ARG 2 -sPDFname=odd_numbers.pdf
ARG 3 -sDSCname=C:\Users\Pieter\AppData\Local\Temp\x_6F65.tmp
ARG 4 pdf2dsc.ps
ARG 5 -c quit
==> 115
ERROR: -101
GS: (C:\Program Files\gs\gs9.15\bin\gsdll64.dll)
ARG 0 -dBATCH
ARG 1 -dMaxBitmap=300000000
ARG 2 -sDEVICE=tiff24nc
ARG 3 -dFirstPage=1
ARG 4 -dLastPage=1
ARG 5 -q
ARG 6 -dNOPAUSE
ARG 7 -dSAFER
ARG 8 -dTextAlphaBits=4
ARG 9 -dGraphicsAlphaBits=4
ARG 10 -g2478x3503
ARG 11 -r300x300
ARG 12 -sOutputFile=C:\Users\Pieter\AppData\Local\Temp\x_6FF2.tmp
ARG 13 odd_numbers.pdf
ARG 14 -c quit
ARG 15 -c quit
==> 233
Error: /typecheck in --aload--
Operand stack:
   --dict:18/18(L)--   --dict:18/18(L)--   1.0   1.0   1.0
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1
%stopped_push   1983   1   3   %oparray_pop   1982   1   3   %oparray_pop   1966   1   3   %oparray_pop   --nostringval--   --nostringval--   2   1   1   --nostringval--
  %for_pos_int_continue   --nostringval--   --nostringval--   false   1   %stopped_push   --nostringval--   --nostringval--   --nostringval--   %array_continue   --nostri
ngval--   --nostringval--   --nostringval--   --nostringval--   --nostringval--   %loop_continue   --nostringval--
Dictionary stack:
   --dict:1194/1684(ro)(G)--   --dict:1/20(G)--   --dict:82/200(L)--   --dict:82/200(L)--   --dict:116/127(ro)(G)--   --dict:280/300(ro)(G)--   --dict:28/32(L)--   --dict
:6/8(L)--   --dict:24/40(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 9.15: Unrecoverable error, exit code 1
ERROR: -100
Unrecoverable error: typecheck in if
Operand stack:
    --nostringval--  false  false  --nostringval--
my_error_exit...<Not a JPEG file: starts with 0x25 0x50>
  Error: Don't know how to read this picture (odd_numbers.pdf)


I was reported to me that PDFs often fail to convert or be opened when they contain abnormal page numbering. I have no idea if this is relevant but it turned out be true for lots of PDFs containing alternating kinds op page numbering like in the PDF I have provided.

kind regards,

Pieter
Comment 1 Ken Sharp 2015-02-23 03:56:58 UTC
The PDF file has an annotation with no appearance stream. This forces Ghostscript to try and create an appearance for the annotation. In the course of this (with this file) the PDF interpreter tries to parse the DA (Default Appearance) and fails to load a colour specification, throwing an error. Technically we could do anything with an annotation which has no appearance, including doing nothing, but for a lot of them we try to draw 'seomthing'.

Current code ignores the error and continues to process the file (although, obviously it doesn't draw the annotation).

I do see a minor problem with the processing of colours in the DA, and that's what causes the error to be thrown. I've altered that and committed it as commit 1125d53f8db9f7402f37fa8fe7823257e4c6554a

Although the prima facie cause was already fixed (so a 'worksforme would be exepcted), I'm closing this as 'fixed' because the file did highlight an underlying fault which I've corrected (thanks for reporting this by the way).


The page numbering is not the problem here, its an annotation. The red grid starting 'Aannemersbedrijf' on the line 'Constructeur' has an annotation with Contents which looks like it ought to say 'Dig' (and with Acrobat, it does). However, the DA (Default Appearance) which is used to set up the graphics state for drawing the annotation does not set the font, or CTM, but does set the colour. To white.....

The result of this is that when Ghostscript tries to create an appearance it draws it with an inappropriate font, and draws the text in white, so it doesn't appear.

Acrobat by contrast uses the 'Rich Text' content to generate a new annotation appearance. These are XML strings and we don't support them (we are a PDF interpreter, not an XML parser), which is why our rendering is always going to be different, we follow the PDF syntax.
Comment 2 gunst.pieter 2015-02-23 04:38:37 UTC
(In reply to Ken Sharp from comment #1)

Thanks for the quick and detailed response (and of course the fix :-)).