[bug-gs] possible bug, use of indirect objects in .pdf
Ray Johnston
ray.johnston@artifex.com
Tue, 02 Sep 2003 11:56:30 -0700
Lobi,
Obviously we've never encountered a file with an indirect element
in a MediaBox. I agree that the PDF specification allows indirect
elements.
The way Ghostscript processes arrays (and dictionaries, for that
matter) is to defer the resolution of indirect objects until the
objects are needed. Unfortunately, this means that we have to
resolve the indirect objects everyplace they are used. Most places
have been handled, but there are a few places that sneak through.
The patch to handle MediaBox (and Cropbox) isn't difficult, but the
placement of the patch depends on the version of Ghostscript (the
area in pdf_main.ps has been subject to frequent changes to add
features such as -dPDFFitPage).
What is needed is to perform 'oforce' on the array prior to its use.
The PostScript snippet to do this is:
mark exch { oforce } forall ]
so if your pdf_main.ps has a section like:
1 index /MediaBox pget {
% Set the page size.
boxrect 2 array astore /PageSize exch def pop pop
} if
change it to:
1 index /MediaBox pget {
mark exch { oforce } forall ] % resolve indirect references in the array
% Set the page size.
boxrect 2 array astore /PageSize exch def pop pop
} if
This change would need to be made every place MediaBox is used.
Another way to fix this would be to change the handling of ']' in
pdf_ops.ps, but performing 'oforce' on all array elements as the array
is stored might decrease the efficiency of execution if some elements
of the array are never referenced.
I'll think about these two approaches and decide which I like the best.
Regards,
Ray Johnston
_______________________________________________________________________
Lobinger Andreas ICM MP P TI 6 wrote:
> Hello,
>
> i'm currently experimenting with .pdfs and and of course i'm testing
> my generated files with gs also. Recently a came across the following
> behaviour of gs which is different to acroread.
>
> I have two versions of the smallest possible .pdf. No page descriptions,
> only root, single object page tree and a page object containing a
> MediaBox only.
>
> lobingera@athene: more exp1.pdf
> %PDF-1.3
> 1 0 obj
> << /Type /Catalog
> /Pages 2 0 R
> >>
> endobj
> 2 0 obj
> << /Type /Pages
> /Kids [3 0 R]
> /Count 1
> >>
> endobj
> 3 0 obj
> << /Type /Page
> /Parent 2 0 R
> /MediaBox [0 0 200 150]
> >>
> endobj
> 4 0 obj
> 200
> endobj
> xref
> 0 5
> 0000000000 65535 f
> 0000000009 00000 n
> 0000000065 00000 n
> 0000000132 00000 n
> 0000000214 00000 n
> trailer <<
> /Size 5
> /Root 1 0 R >>
> startxref
> 233
> %%EOF
> lobingera@athene: more exp2.pdf
> %PDF-1.3
> 1 0 obj
> << /Type /Catalog
> /Pages 2 0 R
> >>
> endobj
> 2 0 obj
> << /Type /Pages
> /Kids [3 0 R]
> /Count 1
> >>
> endobj
> 3 0 obj
> << /Type /Page
> /Parent 2 0 R
> /MediaBox [0 0 4 0 R 150]
> >>
> endobj
> 4 0 obj
> 200
> endobj
> xref
> 0 5
> 0000000000 65535 f
> 0000000009 00000 n
> 0000000065 00000 n
> 0000000132 00000 n
> 0000000216 00000 n
> trailer <<
> /Size 5
> /Root 1 0 R >>
> startxref
> 235
> %%EOF
> lobingera@athene: gs exp1.pdf
> AFPL Ghostscript 8.00 (2002-11-21)
> Copyright (C) 2002 artofcode LLC, Benicia, CA. All rights reserved.
> This software comes with NO WARRANTY: see the file PUBLIC for details.
> Processing pages 1 through 1.
> Page 1
>
>>>showpage, press <return> to continue<<
>
>
> GS>quit
> lobingera@athene: gs exp2.pdf .pdf
> AFPL Ghostscript 8.00 (2002-11-21)
> Copyright (C) 2002 artofcode LLC, Benicia, CA. All rights reserved.
> This software comes with NO WARRANTY: see the file PUBLIC for details.
> Processing pages 1 through 1.
> Page 1
> Error: /typecheck in --sub--
> Operand stack:
> --dict:3/3(L)-- --dict:46/46(ro)(L)-- 0 0 150 --nostringval--
> 0
> Execution stack:
> %interp_exit .runexec2 --nostringval-- --nostringval--
> --nostringval-- 2 %stopped_push --nostringval-- --nostringval--
> --nostringval-- false 1 %stopped_push 1 3 %oparray_pop 1 3
> %oparray_pop 1 3 %oparray_pop --nostringval-- 2 1 1
> --nostringval-- %for_pos_int_continue --nostringval-- --nostringval--
> --nostringval-- --nostringval-- --nostringval-- --nostringval--
> Dictionary stack:
> --dict:1043/1123(ro)(G)-- --dict:0/20(G)-- --dict:79/200(L)--
> --dict:79/200(L)-- --dict:100/127(ro)(G)-- --dict:230/230(ro)(G)--
> --dict:19/24(L)-- --dict:2/5(L)--
> Current allocation mode is local
> AFPL Ghostscript 8.00: Unrecoverable error, exit code 1
>
> exp2.pdf differs from exp1.pdf only in one point. The MediaBox contains a
> indirect reference: [0 0 200 150] vs [0 0 4 0 R 150]. The acrobat Reader
> does read both files without any warnings/errors.
>
> The PDRRef14 says:
> - The MediaBox must be a Rectangle (p88, table 3.19, Entries in a page
> object)
> - A Rectangle is a array of four numbers (p101, section 3.8.3 Rectangles)
> AND:
> - Any object in a PDF ?le may be labeled as an indirect object. (p39,
> section 3.2.9
> Indirect objects).
>
> I'm not aware of any tool that uses indirect references in Rectangles when
> producing .pdfs. But i didn't find any objections about not doing it in the
> spec. The acrobat Reader does read and display both versions and also
> even more complicated documents. So what do do?
>
> If you want to test it by yourself, you should be able to copy the text of
> exp[12].pdf out from this email, save it to a file and use it, AS LONG
> as you make sure that the EOL marker is single char only.
>
> Hoping for an answer and whishing a happy day
> LOBI
>
>
>
>
>
> _______________________________________________
> bug-gs mailing list
> bug-gs@ghostscript.com
> http://www.ghostscript.com/mailman/listinfo/bug-gs
>
>
--
Ray Johnston
Director of Engineering
Artifex Software Inc.
______________________________________________________________________