gbranden pushed a commit to branch master
in repository groff.

commit 112ec43851228e1e4f68e8477aa3de6606a98e0e
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Nov 20 20:41:07 2026 -0600

    [grotty]: Fix Savannah #68942.
    
    * src/devices/grotty/tty.cpp (tty_printer::add_char): When making a
      large vertical motion that far exceeds the existing page length,
      double the size of the page's line count _until_ the new vertical
      position (`vpos`) lies within it, instead of only once.  Check for
      integer overflow when increasing the page length and throw fatal error
      if it occurs.
    
    Fixes <https://savannah.gnu.org/bugs/?68942>.  Problem introduced by me
    in commit b5ede708b9, 17 March, when revising memory management strategy
    to address Savannah #68145.
---
 ChangeLog                  | 13 +++++++++++++
 src/devices/grotty/tty.cpp |  6 +++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 676c4600e..7acadc26c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2026-11-20  G. Branden Robinson <[email protected]>
+
+       * src/devices/grotty/tty.cpp (tty_printer::add_char): When
+       making a large vertical motion that far exceeds the existing
+       page length, double the size of the page's line count _until_
+       the new vertical position (`vpos`) lies within it, instead of
+       only once.  Check for integer overflow when increasing the page
+       length and throw fatal error if it occurs.
+
+       Fixes <https://savannah.gnu.org/bugs/?68942>.  Problem
+       introduced by me in commit b5ede708b9, 17 March, when revising
+       memory management strategy to address Savannah #68145.
+
 2026-11-21  G. Branden Robinson <[email protected]>
 
        [grotty]: Regression-test Savannah #68942.
diff --git a/src/devices/grotty/tty.cpp b/src/devices/grotty/tty.cpp
index b7d0cbfc1..81b0bd3c8 100644
--- a/src/devices/grotty/tty.cpp
+++ b/src/devices/grotty/tty.cpp
@@ -425,7 +425,11 @@ void tty_printer::add_char(output_character c, int w,
       tty_glyph **old_lines = lines;
       // If we exceed the previous page length, double the size so that
       // we don't thrash the allocator.  See Savannah #68145.
-      int new_nlines = nlines * 2;
+      int new_nlines = nlines;
+      while (vpos > new_nlines)
+       new_nlines *= 2;
+      if (new_nlines < 0)
+       fatal("vertical motion to line %1 is too large", vpos);
       lines = 0 /* nullptr */;
       try {
        lines = new tty_glyph *[new_nlines];

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

Reply via email to