gbranden pushed a commit to branch master
in repository groff.

commit 129605355239f448ba517a807e0f3bf46fdeb52e
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu Mar 19 11:34:34 2026 -0500

    [troff]: Fix Savannah #66547.
    
    * src/roff/troff/input.cpp (transparent_throughput_file_request):
      Disallow all grout-invalid characters in "safer" transparent file
      throughput (implemented by the `trf` request), including all C0
      control code points except the line feed (Unix newline), and all C1
      controls and Latin-1 extension code points.  Revise warning diagnostic
      message.
    
    * doc/groff.texi.in (Host System Service Access, Warnings):
    * man/groff.7.man (Request short reference):
    * man/groff_diff.7.man (New requests):
    * src/roff/troff/troff.1.man (Warnings):
    * NEWS: Document it.
    
    Fixes <https://savannah.gnu.org/bugs/?66547>.
    
    Illustration:
    
    $ printf '# foo\0\001\002\003\004\005\006\007\241bar\n# baz\n' >| 
ATTIC/bad-trf
    $ printf '.trf ATTIC/bad-trf\n' | ./build/test-groff -ww -Z
    x T ps
    x res 72000 1 1
    x init
    p1
    troff:<standard input>:1: warning: character code 0 is invalid in 
transparent file throughput; ignoring [-w input]
    troff:<standard input>:1: warning: character code 1 is invalid in 
transparent file throughput; ignoring [-w input]
    troff:<standard input>:1: warning: character code 2 is invalid in 
transparent file throughput; ignoring [-w input]
    troff:<standard input>:1: warning: character code 3 is invalid in 
transparent file throughput; ignoring [-w input]
    troff:<standard input>:1: warning: character code 4 is invalid in 
transparent file throughput; ignoring [-w input]
    troff:<standard input>:1: warning: character code 5 is invalid in 
transparent file throughput; ignoring [-w input]
    troff:<standard input>:1: warning: character code 6 is invalid in 
transparent file throughput; ignoring [-w input]
    troff:<standard input>:1: warning: character code 7 is invalid in 
transparent file throughput; ignoring [-w input]
    troff:<standard input>:1: warning: character code 161 is invalid in 
transparent file throughput; ignoring [-w input]
    \# foobar
    \# baz
    x trailer
    V792000
    x stop
    
    (Comment characters are backslash-prefixed when leading a line to keep
    Git from discarding them from this commit log message.)
---
 ChangeLog                  | 18 ++++++++++++++++++
 NEWS                       |  5 +++++
 doc/groff.texi.in          | 28 ++++++++++++++++++++--------
 man/groff.7.man            | 18 ++++++++++++------
 man/groff_diff.7.man       | 30 ++++++++++++++++++++++++------
 src/roff/troff/input.cpp   |  6 +++---
 src/roff/troff/troff.1.man |  4 +++-
 7 files changed, 85 insertions(+), 24 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b2044b449..54480a7fe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2026-03-19  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/input.cpp
+       (transparent_throughput_file_request): Disallow all
+       grout-invalid characters in "safer" transparent file throughput
+       {implemented by the `trf` request}, including all C0 control
+       code points except the line feed (Unix newline), and all C1
+       controls and Latin-1 extension code points.  Revise warning
+       diagnostic message.
+
+       * doc/groff.texi.in (Host System Service Access, Warnings):
+       * man/groff.7.man (Request short reference):
+       * man/groff_diff.7.man (New requests):
+       * src/roff/troff/troff.1.man (Warnings):
+       * NEWS: Document it.
+
+       Fixes <https://savannah.gnu.org/bugs/?66547>.
+
 2026-03-19  G. Branden Robinson <[email protected]>
 
        * src/devices/grotty/tty.cpp (tty_printer::end_page): Further
diff --git a/NEWS b/NEWS
index e9c153903..3cb4aff27 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,11 @@ troff
 *  GNU troff, the formatter, now issues warnings in the "delim",
    "syntax", and "escape" categories by default.
 
+*  The `trf` (transparent file throughput) request now discards input
+   characters that are invalid in GNU troff's output format, meaning all
+   8-bit character codes less than decimal 32 (except 10, the line feed)
+   and greater than decimal 127.
+
 *  A new read-only register `.ul` reports the count of productive input
    lines remaining to be be underlined in the environment (as configured
    by either the `cu` or `ul` requests).
diff --git a/doc/groff.texi.in b/doc/groff.texi.in
index 7f6a87a22..507f10d78 100644
--- a/doc/groff.texi.in
+++ b/doc/groff.texi.in
@@ -20036,7 +20036,8 @@ in
 @cindex mode, copy, and @code{trf} request
 Break and copy the contents of
 @var{file}
-as ``throughput'' to GNU
+as ``throughput'' to
+GNU
 @command{troff}'s
 output.
 Each line of
@@ -20057,20 +20058,29 @@ GNU
 @command{troff} @c GNU
 performs the copy only when the diversion is emitted.
 
-@cindex @code{trf} request, and invalid characters
-@cindex characters, invalid for @code{trf} request
-@cindex invalid characters for @code{trf} request
 @code{cf} copies the contents of @var{file} completely unprocessed;
 it is therefore an error to use this request in safer mode,
 which is the default.
-Invoke GNU
+Invoke
+GNU
 @command{troff} @c GNU
 or a front end with the
 @option{-U}
 option to enable unsafe mode.
 
-@code{trf} discards invalid input characters;
-recall @ref{Input Format}.
+@cindex @code{trf} request, and invalid characters
+@cindex characters, invalid for @code{trf} request
+@cindex invalid characters for @code{trf} request
+@code{trf}
+discards input characters that are invalid in
+GNU
+@command{troff}'s @c GNU
+output format,
+meaning all 8-bit character codes less than decimal 32
+(except 10,
+the line feed)
+and greater than decimal 127.@footnote{@xref{GNU
+@command{troff} Output}.}
 
 For @code{cf}, within a diversion, ``completely unprocessed'' means that
 each line of a file to be inserted is handled as if it were preceded by
@@ -21713,7 +21723,9 @@ A request was invoked with a mandatory argument absent.
 
 @item input
 @itemx 16384
-An invalid character occurred on the input stream.
+An invalid character occurred on the input stream,
+or was present in the contents of a file processed
+as transparent throughput.
 
 @item escape
 @itemx 32768
diff --git a/man/groff.7.man b/man/groff.7.man
index 5cc69fd48..fae1fcffc 100644
--- a/man/groff.7.man
+++ b/man/groff.7.man
@@ -5377,18 +5377,24 @@ output
 (see
 .MR groff_out @MAN5EXT@ ).
 .
-Unlike
-.request cf ,
-characters invalid as input to GNU
-.I troff \" GNU
-are discarded.
-.
 If
 .IR file 's
 contents do not end with a newline,
 .B trf
 appends one.
 .
+Unlike
+.request cf ,
+.B trf
+discards input characters that are invalid in
+GNU
+.IR troff 's \" GNU
+output format,
+meaning all 8-bit character codes less than decimal 32
+(except 10,
+the line feed)
+and greater than decimal 127.
+.
 .TPx
 .REQ .trin abcd\fR\&.\|.\|.\&\fP
 As
diff --git a/man/groff_diff.7.man b/man/groff_diff.7.man
index c26c82e4b..2b3405cb1 100644
--- a/man/groff_diff.7.man
+++ b/man/groff_diff.7.man
@@ -12,7 +12,7 @@ and AT&T
 .\" ====================================================================
 .\"
 .\" Copyright 1989-2024 Free Software Foundation, Inc.
-.\"           2019-2025 G. Branden Robinson
+.\"           2019-2026 G. Branden Robinson
 .\"
 .\" This file is part of groff, the GNU roff typesetting system.
 .\"
@@ -4526,12 +4526,10 @@ but does not append a newline.
 .BI .trf\~ file
 Break and copy
 .I file
-as \[lq]throughput\[rq] to GNU
+as \[lq]throughput\[rq] to
+GNU
 .I troff \" GNU
-output,
-discarding characters that are invalid as input;
-contrast with
-.BR cf .
+output.
 .
 Each line of
 .I file
@@ -4549,6 +4547,26 @@ Invoking the request
 with the no-break control character
 suppresses the break.
 .
+If a diversion is in use,
+GNU
+.I troff \" GNU
+performs the copy only when the diversion is emitted.
+.
+.
+.IP
+.B trf
+discards input characters that are invalid in
+GNU
+.IR troff 's \" GNU
+output format,
+meaning all 8-bit character codes less than decimal 32
+(except 10,
+the line feed)
+and greater than decimal 127.
+.
+See
+.MR groff_out @MAN5EXT@ .
+.
 .
 .TP
 .BI .trin\~ abcd
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 659350a2c..9b7ee46af 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -9563,9 +9563,9 @@ static void transparent_throughput_file_request()
          int c = getc(fp);
          if (c == EOF)
            break;
-         if (is_invalid_input_char(c))
-           warning(WARN_INPUT, "invalid input character code %1",
-                   int(c));
+         if ((c != '\n') && ((c < 32) || (c > 127)))
+           warning(WARN_INPUT, "character code %1 is invalid in"
+                   " transparent file throughput; ignoring", int(c));
          else {
            curdiv->transparent_output(c);
            reading_beginning_of_input_line = c == '\n';
diff --git a/src/roff/troff/troff.1.man b/src/roff/troff/troff.1.man
index 1364e2a3b..cd8339586 100644
--- a/src/roff/troff/troff.1.man
+++ b/src/roff/troff/troff.1.man
@@ -708,7 +708,9 @@ T}
 .
 .sp \n[PD]u
 input  16384   T{
-An invalid character occurred on the input stream.
+An invalid character occurred on the input stream,
+or was present in the contents of a file processed
+as transparent throughput.
 T}
 .
 .

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to