Package: gv
Version: 1:3.6.1-9
Severity: normal

In certain cases the ps file scanner can get confused by ps files
embedded within a page.  The file
<http://www.inference.phy.cam.ac.uk/sanjoy/bug/gv/several-pages.ps>,
extracted from a colleague's textbook, shows the problem.  Running gv
several-pages.ps shows only page "540,54" (really "540,541") in the
page list.  But the file has a few pages: (540,541) and (543,542) and
(639,638).  On my laptop (Pentium 3) all versions of gs (v8.01, 8.14,
and 8.50) show the full set of pages, so I the problem is most likely
in gv.

The
<http://www.inference.phy.cam.ac.uk/sanjoy/bug/gv/difficult-page.ps>
file has the difficult page itself, without the huge prolog (all those
tex fonts) or the pages after it.

Also, the vanilla gv 3.6.1, say from the gv_3.6.1.orig.tar.gz file,
shows all the pages in the sidebar.  So the problem is probably in a
Debian patch.  By trying various partial patches and guessing a bit, I
narrowed it down to this hunk from
debian/patches/02_293976=045735_filename+unknown.diff (available after
doing 'apt-src install gv/unstable'), which applies to the readline()
routine:

--- gv-3.6.1.orig/src/ps.c
+++ gv-3.6.1/src/ps.c
@@ -1826,7 +1858,12 @@
    else
 #endif
    if  (!IS_COMMENT("Begin"))     {} /* Do nothing */
-   else if IS_BEGIN("Document:")  SKIP_UNTIL_1("EndDocument")
+   else if IS_BEGIN("Document:")  {  /* Skip the EPS without handling its 
content */
+            while (line && !IS_END("Document")) {
+               line = ps_io_fgetchars(fd,-1);
+               if (line) *line_lenP += FD_LINE_LEN;
+            }
+   }
    else if IS_BEGIN("Feature:")   SKIP_UNTIL_1("EndFeature")
 #ifdef USE_ACROREAD_WORKAROUND
    else if IS_BEGIN("File")       SKIP_UNTIL_2("EndFile","EOF")

(also available at
<http://www.inference.phy.cam.ac.uk/sanjoy/bug/gv/causes-bug.diff>)

The culprit seems to be the change from SKIP_UNTIL_1("EndDocument") to
the while loop.  SKIP_UNTIL_1() calls readline(), which skips over
embedded ps documents.  The while loop, however, blindly reads to the
next %%EndDocument.  The difference shows up when an included ps
document includes a ps document, as the troublesome page does.  Here
is its structure:

$ egrep '^%%(Begin|End)Document' difficult-page.ps 
%%BeginDocument: /home/mackay/handbook/figs/inter/sc_a1.blank.ps
%%BeginDocument: EPSF
%%EndDocument
%%EndDocument
%%BeginDocument: /home/mackay/handbook/figs/inter/sc_a2b.blank.ps
%%BeginDocument: EPSF
%%EndDocument
%%EndDocument
%%BeginDocument: /home/mackay/handbook/figs/inter/sc_a3.blank.ps
%%BeginDocument: EPSF
%%EndDocument
%%EndDocument
%%BeginDocument: /home/mackay/handbook/figs/test_train.eps
%%EndDocument
%%BeginDocument: /home/mackay/handbook/figs/probability.eps
%%EndDocument
%%BeginDocument: /home/mackay/handbook/figs/error_bar_net.ps
%%EndDocument

So the first document includes another document.  With the patch, the
scanner will get to the first BeginDocument, then skip to the first
EndDocument, which matches the *second* BeginDocument.  But the second
BeginDocument gets skipped over, so the scanner should be quite
confused!

Now, I'm not sure whether the analysis above is totally right.  But
applying the patch above produces the bug, and reverting it removes
the bug.  And the behavior with the patch seems to be incorrect and
worth fixing.

Although perhaps the embedded ps file is part of the problem?  It was
created by gnuplot and is basically an EPS file surrounded by a few
lines to turn it into a regular PS file -- probably one is asking for
trouble by including it.  That section of 'several-pages.ps' begins:

%%BeginDocument: /home/mackay/handbook/figs/inter/sc_a2b.blank.ps
%!PS-Adobe-2.0
%%Creator: gnuplot
%%DocumentFonts: Courier
%%DocumentNeededFonts: Courier
%%Pages: (atend)
%%BoundingBox: 46 50 550 770
%%EndComments
/GnuTransform {
  90 rotate
  50 -550 translate
  2 2 scale
} def
%%EndProlog
%%Page: ? 1
gsave
GnuTransform
%%BeginDocument: EPSF
1 dict begin
/showpage {} def
%!PS-Adobe-2.0 EPSF-2.0
%%Creator: gnuplot
%%DocumentFonts: Courier
%%DocumentNeededFonts: Courier
%%BoundingBox: 0 0 360 252
%%EndComments

So gnuplot was doing something funky by making an EPS file and
wrapping a few lines of ps around it to handle the scaling and moving
the figure towards the center of the page.

-- System Information:
Debian Release: 3.1
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.4.27-200503091
Locale: LANG=en_US, LC_CTYPE=en_US (charmap=ISO-8859-1)

Versions of packages gv depends on:
ii  gs                       8.01-5          Transitional package
ii  gs-afpl [gs]             8.14-3          The AFPL Ghostscript PostScript in
ii  gs-gpl [gs]              8.01-5          The GPL Ghostscript PostScript int
ii  libc6                    2.3.2.ds1-20    GNU C Library: Shared libraries an
ii  libice6                  4.3.0.dfsg.1-10 Inter-Client Exchange library
ii  libsm6                   4.3.0.dfsg.1-10 X Window System Session Management
ii  libx11-6                 4.3.0.dfsg.1-10 X Window System protocol client li
ii  libxext6                 4.3.0.dfsg.1-10 X Window System miscellaneous exte
ii  libxmu6                  4.3.0.dfsg.1-10 X Window System miscellaneous util
ii  libxpm4                  4.3.0.dfsg.1-10 X pixmap library
ii  libxt6                   4.3.0.dfsg.1-10 X Toolkit Intrinsics
ii  xaw3dg                   1.5+E-8         Xaw3d widget set
ii  xlibs                    4.3.0.dfsg.1-10 X Keyboard Extension (XKB) configu

-- no debconf information


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to