Hi Jan,

Jan Stary wrote on Fri, Oct 06, 2017 at 01:34:03PM +0200:

> This is current/amd64. I just produced a pdf of bc(1) with
> "man -Tpdf bc > bc.pdf".
> 
> Trying to view that pdf with mupdf(1) complains thusly:
> (I can view and print the PDF fine though)
> 
>       warning: expected 'endobj' or 'stream' keyword (27 0 R)
>       warning: expected 'endobj' or 'stream' keyword (9 0 R)
>       warning: expected 'endobj' or 'stream' keyword (4 0 R)
>       warning: expected 'endobj' or 'stream' keyword (3 0 R)
>       warning: expected 'endobj' or 'stream' keyword (5 0 R)
> 
> Trying to view that pdf with gv(1) says
> 
> Error: /typecheck in --setfileposition--
> Operand stack:
[...]
> and errors out.
> 
> Is seems to happen with any other manpage as well.
> Is anyone seeing the same?

Apparently, bugs are immortal: they never die from old age.

This was a group of three bugs all more than seven years old.
Quite an accomplishment to find bugs of that age in mandoc,
given how often much of the code kept getting re-written and
re-re-written while we slowly learnt how languages work.

But it looks like nobody ever bothered to check whether the PDF
output generated by mandoc(1) was syntactically valid - which is
amazing...

Thanks for the report, fixed by the commit below.
  Ingo


Log Message:
-----------
Properly close out the top-level Font object, the end-of-page
Resource objects, and the Catalog object, fixing three PDF syntax 
errors that were present in every PDF file generated with mandoc
since the initial checkin of the formatter in July 2010.
Bug reported by Jan Stary <hans at stare dot cz> on misc@.

Modified Files:
--------------
    mandoc:
        term_ps.c

Revision Data
-------------
Index: term_ps.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/term_ps.c,v
retrieving revision 1.85
retrieving revision 1.86
diff -Lterm_ps.c -Lterm_ps.c -u -p -r1.85 -r1.86
--- term_ps.c
+++ term_ps.c
@@ -759,7 +759,7 @@ ps_closepage(struct termp *p)
                ps_printf(p, "/Font <<\n");
                for (i = 0; i < (int)TERMFONT__MAX; i++)
                        ps_printf(p, "/F%d %d 0 R\n", i, 3 + i);
-               ps_printf(p, ">>\n>>\n");
+               ps_printf(p, ">>\n>>\nendobj\n");
 
                /* Page node. */
                pdf_obj(p, base + 3);
@@ -824,7 +824,7 @@ ps_end(struct termp *p)
        ps_printf(p, "<<\n");
        ps_printf(p, "/Type /Catalog\n");
        ps_printf(p, "/Pages 2 0 R\n");
-       ps_printf(p, ">>\n");
+       ps_printf(p, ">>\nendobj\n");
        xref = p->ps->pdfbytes;
        ps_printf(p, "xref\n");
        ps_printf(p, "0 %zu\n", base + 1);
@@ -918,7 +918,7 @@ ps_begin(struct termp *p)
                        ps_printf(p, "/Subtype /Type1\n");
                        ps_printf(p, "/Name /F%d\n", i);
                        ps_printf(p, "/BaseFont /%s\n", fonts[i].name);
-                       ps_printf(p, ">>\n");
+                       ps_printf(p, ">>\nendobj\n");
                }
        }
 

Reply via email to