This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch tymux-10-quiet-head
in repository terminology.

View the commit online.

commit bd12422cf72de16a6a0224b58b04fea28d3c55e7
Author: Boris Faure <[email protected]>
AuthorDate: Sat Nov 7 16:56:34 2026 +0000

    termptyesc: clamp rectangle bottom and right before adding the margins
    
    With the cursor restricted to the margins (DECOM), the rectangle and
    from-to operations (DECFRA, DECERA, DECCARA, DECRARA) add the top and
    left margins to the bottom and right arguments, which go up to
    INT32_MAX: the sum overflowed to a negative value that slipped under
    the screen clamp, and DECCARA wrote millions of cells past the end of
    the screen. Found by AFL. Out-of-range values are now clamped to the
    screen first, which gives the same rectangle for every value that did
    not overflow.
    
    The bottom clamp after the 1-based to 0-based conversion let the line
    just below the screen through. TERMPTY_SCREEN() wraps it onto the
    first line: with a bottom margin at the last line, as DECSTBM 5;24 on
    24 lines stores it, a rectangle ending one line past the margin area
    also changed the first line.
    
    rect-huge-args.sh crashes without the fix.
---
 src/bin/termptyesc.c    | 12 ++++++------
 tests/rect-huge-args.sh | 36 ++++++++++++++++++++++++++++++++++++
 tests/tests.results     |  1 +
 3 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 182249a3..63a3aa41 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -1885,7 +1885,7 @@ _clean_up_rect_coordinates(Termpty *ty,
      }
    left--;
 
-   if (right < 1)
+   if ((right < 1) || (right > ty->w))
      right = ty->w;
    if (ty->termstate.restrict_cursor)
      {
@@ -1896,7 +1896,7 @@ _clean_up_rect_coordinates(Termpty *ty,
    if (right > ty->w)
      right = ty->w;
 
-   if (bottom < 1)
+   if ((bottom < 1) || (bottom > ty->h))
      bottom = ty->h;
    if (ty->termstate.restrict_cursor)
      {
@@ -1905,7 +1905,7 @@ _clean_up_rect_coordinates(Termpty *ty,
           bottom = ty->termstate.bottom_margin;
      }
    bottom--;
-   if (bottom > ty->h)
+   if (bottom >= ty->h)
      bottom = ty->h - 1;
 
    if ((bottom < top) || (right < left))
@@ -1951,7 +1951,7 @@ _clean_up_from_to_coordinates(Termpty *ty,
      }
    left--;
 
-   if (right < 1)
+   if ((right < 1) || (right > ty->w))
      right = ty->w;
    if (ty->termstate.restrict_cursor)
      {
@@ -1962,7 +1962,7 @@ _clean_up_from_to_coordinates(Termpty *ty,
    if (right > ty->w)
      right = ty->w;
 
-   if (bottom < 1)
+   if ((bottom < 1) || (bottom > ty->h))
      bottom = ty->h;
    if (ty->termstate.restrict_cursor)
      {
@@ -1971,7 +1971,7 @@ _clean_up_from_to_coordinates(Termpty *ty,
           bottom = ty->termstate.bottom_margin;
      }
    bottom--;
-   if (bottom > ty->h)
+   if (bottom >= ty->h)
      bottom = ty->h - 1;
 
    if ((bottom == top) && (right < left))
diff --git a/tests/rect-huge-args.sh b/tests/rect-huge-args.sh
new file mode 100755
index 00000000..0284a1fb
--- /dev/null
+++ b/tests/rect-huge-args.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+# rectangle operations with the bottom and right arguments at INT32_MAX
+# while the cursor is restricted to the margins: adding the margins must
+# not overflow them past the screen clamp
+
+# fill space with E
+printf '\033#8'
+# set top/bottom margins
+printf '\033[5;20r'
+# allow and set left/right margins
+printf '\033[?69h\033[10;70s'
+# restrict cursor
+printf '\033[?6h'
+
+for mode in 1 2; do
+   # DECSACE: stream, then rectangle
+   printf '\033[%s*x' "$mode"
+   # DECFRA
+   printf '\033[42;3;3;2147483647;2147483647$x'
+   # DECCARA
+   printf '\033[3;3;2147483647;2147483647;1;4$r'
+   # DECRARA
+   printf '\033[4;4;2147483647;2147483647;7$t'
+   # DECERA
+   printf '\033[8;8;2147483647;2147483647$z'
+done
+
+# bottom margin at the last line: a bottom argument one past the margin
+# area must stop at the last line, not wrap onto the first one
+printf '\033[?69l\033[5;24r\033[1*x'
+printf '\033[43;1;1;21;10$x'
+printf '\033[2*x'
+printf '\033[44;1;20;21;30$x'
+
+printf '\033[?6l\033[r\033[1*x'
diff --git a/tests/tests.results b/tests/tests.results
index f270ce4b..ced754db 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -216,3 +216,4 @@ osc-8.sh d8810df219faf4a8fe84fd08ed922695
 osc-long.sh a94cb70dd58d07f52bbdf0cc5e7b95e1
 decfra-keep-colors.sh 84900ad5b5ffd5a14cb3318f63690691
 osc-50-size.sh 54d79d82f23d7bfaeb693d60bffa17dc
+rect-huge-args.sh ba2946480420ed690b567f7263766b7c

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to