bugGNU roff - Bugs: bug #65320, [pdf] doesn't guard control...

 
 

bug #65320: [pdf] doesn't guard control characters when emitting bookmark diversion

Submitter:  G. Branden Robinson <gbranden>
Submitted:  Fri 16 Feb 2024 03:49:13 PM UTC
   
 
Category:  Macro package - others/general Severity:  3 - Normal
Item Group:  Incorrect behaviour Status:  Postponed
Privacy:  Public Assigned to:  gbranden
Open/Closed:  Open Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 17 Feb 2024 06:02:36 PM UTC, comment #4: 

Blocked by bug #65322.

G. Branden Robinson <gbranden>
Group administrator
Fri 16 Feb 2024 07:27:15 PM UTC, comment #3: 

Exciting.


^351da0dcd troff/input.c            (James Clark         1991-06-02 04:20:34 -0500  626)   assert(level == 0);


G. Branden Robinson <gbranden>
Group administrator
Fri 16 Feb 2024 07:22:51 PM UTC, comment #2: 

There will be a delay in pushing this fix.

It seems to have exposed a way for the mom macro package (perhaps) to provoke an assertion failure in the formatter, which should certainly be impossible.


/usr/bin/mkdir -p `dirname contrib/mom/examples/mom-pdf.pdf` \
&& LC_ALL=C GROFF_COMMAND_PREFIX= GROFF_BIN_PATH="/home/branden/src/GIT/groff/build" PDFMOM_BIN_PATH="." /home/branden/src/GIT/groff/build/pdfmom -F/home/branden/src/GIT/groff/build/font -F/home/branden/src/GIT/groff/build/../font -M/home/branden/src/GIT/groff/build/tmac -M/home/branden/src/GIT/groff/build/../tmac -M../contrib/mom -K utf8 -p -e -t ../contrib/mom/examples/mom-pdf.mom >contrib/mom/examples/mom-pdf.pdf
troff: ../src/roff/troff/input.cpp:626: static int input_stack::finish_get(node**): Assertion `level == 0' failed.
groff: error: troff: Aborted (core dumped)


G. Branden Robinson <gbranden>
Group administrator
Fri 16 Feb 2024 03:56:56 PM UTC, comment #1: 

Tested-by: Alejandro Colomar <alx@kernel.org>

```
alx@debian:~/tmp$ groff -man -Tpdf dot.man >dot.pdf
alx@debian:~/tmp$ open dot.pdf
alx@debian:~/tmp$ groff --version
GNU groff version 1.23.0.902-1fce7-dirty
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software, distributed under the terms of the GNU General Public
License, version 3, or any later version, at your option.  There is NO warranty;
not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

programs called:

GNU grops (groff) version 1.23.0.902-1fce7-dirty
GNU troff (groff) version 1.23.0.902-1fce7-dirty
```

With the above, which has your suggested patch manually applied, I see the PDF bookmark for the subsection, and can't see the warning.

```
alx@debian:~/tmp$ /usr/bin/groff --version
GNU groff version 1.23.0
Copyright (C) 2022 Free Software Foundation, Inc.
GNU groff comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of groff and its subprograms
under the terms of the GNU General Public License.
For more information about these matters, see the file
named COPYING.

called subprograms:

GNU grops (groff) version 1.23.0
GNU troff (groff) version 1.23.0
alx@debian:~/tmp$ /usr/bin/groff -man -Tpdf dot.man >dotold.pdf
troff:dot.man:3: warning: macro 'and' not defined (possibly missing space after 'an')
alx@debian:~/tmp$ open dotold.pdf
```

With the above, I see the warning, and the PDF lacks a bookmark for the subsection.

Alejandro Colomar <alx>
Fri 16 Feb 2024 03:49:13 PM UTC, original submission:  

Alex Colomar reported to the groff list:


> here's [a warning] that I've only seen in -Tpdf.  It might be a bug in
> -Tpdf.
>
>       troff:man7/path_resolution.7:135: warning: macro 'and' not defined
> (possibly missing space after 'an')
>       make: *** [share/mk/build/pdf/troff.mk:22:
> .tmp/man/man7/path_resolution.7.pdf.set] Error 1
>       make: *** Deleting file '.tmp/man/man7/path_resolution.7.pdf.set'
>
> Here's a small reproducer:
>
>       alx@debian:~/tmp$ cat dot.man
>       .TH dot 7 2024-02-16 dots-in-SS
>       .SH Foo
>       .SS . and ..
>       \&. and .. are special files.
>       alx@debian:~/tmp$ groff -man -Tutf8 dot.man >/dev/null
>       alx@debian:~/tmp$ groff -man -Tps dot.man >/dev/null
>       alx@debian:~/tmp$ groff -man -Tpdf dot.man >/dev/null
>       troff:dot.man:3: warning: macro 'and' not defined (possibly missing
> space after 'an')


I can reproduce this with groff 1.23.0 and Git HEAD.

I believe the problem happens because this `nop` request is taking place inside a diversion (a "box" diversion, to be precise).  Consequently when the diversion is later interpolated, it can include macro calls or requests, so the formatter recognizes the control character at the beginning of the (interpolated) input line.  This causes the PDF bookmarks that are automatically constructed from the (sub)section heading texts to be susceptible to misinterpretation.  If you check the PDF generated from your reproducer, you will see that the corresponding bookmark for the subsection is absent.

The solution is to prevent a potential control character that starts the (sub)section heading text from appearing at the beginning of the (interpolated) input line.

Thus we need a dummy character prefix.

Proposed fix:


diff --git a/tmac/pdf.tmac b/tmac/pdf.tmac
index 54175434f..fe12d35da 100644
--- a/tmac/pdf.tmac
+++ b/tmac/pdf.tmac
@@ -253,7 +253,7 @@ .de pdfbookmark
 .         tr \[em]-
 .         nf
 .         box pdf:clean
-.         nop \\$*
+.         nop \&\\$*
 .         fl
 .         box
 .         chop pdf:clean


G. Branden Robinson <gbranden>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Digest:
   bug dependencies.

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by alx (Posted a comment)
  • -email is unavailable- added by gbranden (Submitted the item)
  • -email is unavailable- added by gbranden (original reporter)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-02-17 gbranden StatusIn Progress Postponed
        Dependencies- Depends on bugs #65322
    2024-02-16 gbranden Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.14-f13d.
    Corresponding source code