[gs-bugs] [Bug 691503] Regression: ghostscript produces bad pdf file starting with r8445

bugzilla-daemon at ghostscript.com bugzilla-daemon at ghostscript.com
Thu Jul 29 12:00:49 UTC 2010


--- Comment #4 from Ken Sharp <ken.sharp at artifex.com> 2010-07-29 12:00:48 UTC ---
Created an attachment (id=6575)
 --> (http://bugs.ghostscript.com/attachment.cgi?id=6575)
patch part 2

The problem is not entirely fixable in pdfwrite. We receive a /OUT pdfmark
generated from the PDF interpreter, this references both page 1 and page 2.
pdfwrite duly adds these to the outline tree and writes /DEST entries to the
PDF file.

In order to do this it creates a reference to the second page, which reserves
an object number for it. However, we never get a second page, which means we
end up with a reserved entry pointing at an invalid offset in the PDF file.
This seems to be what the Ghostscript PDF interpreter is complaining about. 

Now the right way to deal with this is not to emit the outline for pages that
don't exist, but there's no way for pdfwrite to know that page 2 won't be
turning up. So the real fix needs to be in the PDF interpreter which should
validate the destinations against the number of pages in the PDF file, and the
first/last pages requested, to ensure that destinations only point at real

I have made a change in the way that pdfwrite works. It now stores pages
initially with an offset of 0 in the xref (which is never legal because of the
PDF header). When writing the xref table, we now check to see if any entries
have an offset of 0 and if they do we write the xref in sections, eliding the
object(s) whose offset is 0.

The resulting PDF file can be opened in Ghostscript again. However its not
ideal because we are still setting an Outline which uses a Dest which is
pointing to a page and object which does not exist.

The attached patches implement this functionality. I'll probably fold this into
the pdfwrite code assuming that a cluster test shows no problems. I'll then
look at fixing the PDF interpreter so it doesn't emit broken pdfmarks either.

Configure bugmail: http://bugs.ghostscript.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

More information about the gs-bugs mailing list