URL: <https://savannah.gnu.org/bugs/?68894>
Summary: [eqn] stream management gets up to shenanigans
Group: GNU roff
Submitter: gbranden
Submitted: Sun 08 Nov 2026 10:10:02 PM UTC
Category: Preprocessor eqn
Severity: 3 - Normal
Item Group: Warning/Suspicious behaviour
Status: Need Info
Privacy: Public
Assigned to: gbranden
Open/Closed: Open
Discussion Lock: Unlocked
Planned Release: None
_______________________________________________________
Follow-up Comments:
-------------------------------------------------------
Date: Sun 08 Nov 2026 10:10:02 PM UTC By: G. Branden Robinson <gbranden>
I wanted to apply the following straightforward patch to the formatter.
diff --git a/ChangeLog b/ChangeLog
index ecea890ae..cabbbfbcb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2026-11-08 G. Branden Robinson <[email protected]>
+
+ * src/roff/troff/input.cpp (file_iterator::peek): Check return
+ value of ungetc(3) and throw fatal diagnostic if pushing back a
+ character to our input stream fails. Such a failure corrupts
+ our input; we can make no useful progress in that eventuality.
+
2026-11-08 G. Branden Robinson <[email protected]>
* src/roff/troff/input.cpp (file_iterator::close): Raise a
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 2b968a2da..0fe6f7b76 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -579,8 +579,13 @@ int file_iterator::peek()
// TODO: process_input_character()
c = getc(fp);
}
- if (c != EOF)
- ungetc(c, fp);
+ if (c != EOF) {
+ int ret = ungetc(c, fp);
+ if (ret != 0)
+ fatal("unexpected end of file while pushing back character code"
+ " %1 to %2 \"%3\"", c, was_popened ? "pipe" : "file",
+ filename);
+ }
return c;
}
I thought that the formatter would either blow up all over the place on tons
of documents, or my change would not alter the success of the build in any
way.
What actually happened was something in between.
The build failed in exactly one place, 6,410 lines into _groff_diff_(7).
$ make -k -C build
make: Entering directory '/home/branden/src/GIT/groff/build'
make all-recursive
make[1]: Entering directory '/home/branden/src/GIT/groff/build'
make[2]: Entering directory '/home/branden/src/GIT/groff/build'
GROFF doc/groff-man-pages.pdf
troff: backtrace: file 'man/groff_char.7':1075
troff:man/groff_char.7:1075: warning: special character '.j' not defined [-w
char]
troff: backtrace: file 'man/groff_char.7':1481
troff:man/groff_char.7:1481: warning: special character 'vA' not defined [-w
char]
troff: backtrace: file 'man/groff_char.7':1611
troff:man/groff_char.7:1611: warning: special character 'bs' not defined [-w
char]
troff: backtrace: file 'man/groff_char.7':1784
troff:man/groff_char.7:1784: warning: special character '-+' not defined [-w
char]
troff: backtrace: file 'man/groff_char.7':1833
troff:man/groff_char.7:1833: warning: special character 'coproduct' not
defined [-w char]
troff: backtrace: file 'man/groff_char.7':1933
troff:man/groff_char.7:1933: warning: special character '+e' not defined [-w
char]
troff: backtrace: file 'man/groff_diff.7':6401
troff:man/groff_diff.7:6401: fatal error: unexpected end of file while pushing
back character code 69 to file "man/groff_diff.7"
pdfmom: fatal error: test-groff exited with status 12
make[2]: *** [Makefile:20001: doc/groff-man-pages.pdf] Error 1
make[2]: *** Deleting file 'doc/groff-man-pages.pdf'
GROFF doc/groff-man-pages.utf8.txt
troff: backtrace: file 'man/groff_diff.7':6401
troff:man/groff_diff.7:6401: fatal error: unexpected end of file while pushing
back character code 69 to file "man/groff_diff.7"
make[2]: *** [Makefile:20011: doc/groff-man-pages.utf8.txt] Error 12
make[2]: *** Deleting file 'doc/groff-man-pages.utf8.txt'
make[2]: Target 'all-am' not remade because of errors.
make[2]: Leaving directory '/home/branden/src/GIT/groff/build'
make[1]: *** [Makefile:13387: all-recursive] Error 1
make[1]: Leaving directory '/home/branden/src/GIT/groff/build'
make: *** [Makefile:7707: all] Error 2
make: Leaving directory '/home/branden/src/GIT/groff/build'
(Character code 69 is a capital E, and intriguingly does not correspond to the
input...except for the names of the special tokens used to delimit _eqn_
input.)
The following reproducer is as minimal as I can make it. I made several
attempts at shortening the token list. All my efforts concealed the bug.
$ cat eqn-bomber.roff
.EQ
x sub 1 ~ y sub 1 ~ ldots ~ x sub n ~ y sub n
.EN
$ ./build/test-groff -ae eqn-bomber.roff
troff:eqn-bomber.roff:101: fatal error: unexpected end of file while pushing
back character code 69 to file "eqn-bomber.roff"
Note that wildly bogus line number, too.
Something *deeply* fishy is going on here.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?68894>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc
Description: PGP signature
