Bug 689791 - gs misparses %%ViewingOrientation and other comments
Summary: gs misparses %%ViewingOrientation and other comments
Status: NOTIFIED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: PS Interpreter (show other bugs)
Version: 8.62
Hardware: All Linux
: P4 normal
Assignee: Alex Cherepanov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-14 19:45 UTC by William Bader
Modified: 2008-12-19 08:31 UTC (History)
0 users

See Also:
Customer:
Word Size: ---


Attachments
sample.ps (14.86 MB, application/postscript)
2008-04-14 19:48 UTC, William Bader
Details
dsc.pat (724 bytes, patch)
2008-04-14 19:53 UTC, William Bader
Details | Diff
improved patch (3.06 KB, patch)
2008-04-20 16:34 UTC, Alex Cherepanov
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description William Bader 2008-04-14 19:45:23 UTC
The gs DSC parser has two problems.  First, it does not respect
BeginData/EndData.  If a page contains an embedded EPS and the embedded EPS has
page setup comments, gs parses the comments in the embedded EPS instead of
ignoring them.  Second, the parser should take the first version of each comment
instead of continuing to scan for other copies.  This second problem makes it
impossible to work-around the first problem by adding more comments at the top.
This is causing me problems where a landscape page with an embedded EPS that
wants to be portrait is causing ps2pdf to write a portrait pdf.
Refer to the parsing rules on page 28 of section 4.4 of Adobe document
5001.DSC_Spec (25 Sep 92).
Comment 1 William Bader 2008-04-14 19:48:13 UTC
Created attachment 3931 [details]
sample.ps

Sample page that ps2pdf sets the wrong orientation because it looks at comments
inside an embedded eps.
Comment 2 William Bader 2008-04-14 19:53:12 UTC
Created attachment 3932 [details]
dsc.pat

Patch to zdscpars.c to ignore comments between begin and end pairs in the bad
list.  This fixes my problem, but there is probably a better way to do it. 
Unpaired begins will cause problems.
Comment 3 Ray Johnston 2008-04-17 10:34:02 UTC
Assigning to Alex to review (and hopefully commit) the patch.
Comment 4 Alex Cherepanov 2008-04-20 16:34:13 UTC
Created attachment 3952 [details]
improved patch

This patch keeps the nesting counter in the dsc_data_t structure instead of the

static variable.
Comment 5 Alex Cherepanov 2008-04-20 16:42:21 UTC
The improved patch is committed as a rev. 8653.
Regression testing shows no differences.
Comment 6 Russell Lang 2008-04-20 18:22:19 UTC
The DSC parser does pay attention to %%BeginData and %%BeginDocument, and skips
over the embedded files.  Ghostscript doesn't make use of this information, but
could be made to ignore DSC comments from embedded files.

The CDSC structure contains the following semi-private variables which could be 
used by Ghostscript to determine if the DSC parser is currently skipping DSC
comments.
    int skip_document;          /* recursion level of %%BeginDocument: */
    int skip_bytes;             /* #bytes to ignore from BeginData: */
                                /* or DOSEPS preview section */
Using these would probably result in a more robust fix.
Comment 7 William Bader 2008-04-21 03:40:48 UTC
The comment in zdscpars.c above the declaration of BadCmdlist says "If we send
the data block type comments, Russell's parser will want to skip the specified
block of data. This is not appropriate for our situation."  Will passing
comments with data length parameters cause problems?