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 8a7734789b9bebeb778bf2a0f3a62aaefbbfecd9
Author: Boris Faure <[email protected]>
AuthorDate: Wed Nov 4 22:03:28 2026 +0000

    termptyesc: resume an incomplete OSC where its scan stopped
    
    An OSC split across reads was scanned again from its start on each
    read, up to its 4096 codepoint buffer: 8 million steps for a long
    title read 1 byte at a time. Found by AFL.
    
    Resume it from ty->seq_scanned, but back over a final ESC the next
    read completes into an ESC \.
    
    tybench, strings corpus, 3 bytes per read: 12.1 MB/s before, 17.4
    after.
---
 src/bin/termptyesc.c | 18 +++++++++++++-----
 tests/osc-long.sh    | 37 +++++++++++++++++++++++++++++++++++++
 tests/tests.results  |  1 +
 3 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 7a5bf4af..cc1d69c7 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -5348,9 +5348,11 @@ _handle_esc_osc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
    int arg;
    int payload_len; /* the OSC string length, without its terminator */
    Eina_Bool bel;   /* the request was terminated by BEL, not ST */
+   unsigned int scanned = ty->seq_scanned;
 
-   cc = c;
-   p = buf;
+   ty->seq_scanned = 0;
+   cc = c + scanned;
+   p = buf + scanned;
    be = buf + sizeof(buf) / sizeof(buf[0]);
    while ((cc < ce) && (*cc != ST) && (*cc != BEL) && (p < be))
      {
@@ -5368,11 +5370,17 @@ _handle_esc_osc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
         p++;
         cc++;
      }
+   if (cc == ce)
+     {
+        /* the last codepoint may be the ESC of a split ESC \ */
+        if ((cc > c) && (*(cc - 1) == ESC))
+          cc--;
+        return _seq_incomplete(ty, c, cc);
+     }
+   if (scanned)
+     memcpy(buf, c, scanned * sizeof(Eina_Unicode));
    if (p == be)
      {
-        /* the last copied codepoint may be the ESC of a split ESC \ */
-        if (cc == ce)
-          return 0;
         ty->osc_skip = 1;
         ty->osc_skip_esc = 0;
         _osc52_long_start(ty, buf, be);
diff --git a/tests/osc-long.sh b/tests/osc-long.sh
new file mode 100644
index 00000000..11ed67a4
--- /dev/null
+++ b/tests/osc-long.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+# shellcheck source=tests/utils.sh
+. "$(dirname "$0")/utils.sh"
+
+# $1: the number of times to repeat $2
+repeat()
+{
+    head -c "$1" /dev/zero | tr '\0' "$2"
+}
+
+# An OSC split across reads resumes its scan where it stopped, and is set
+# once whatever the read sizes
+
+# clear screen
+printf '\033[2J'
+
+# move to 0; 0
+printf '\033[0;0H'
+
+# a long title closed by BEL
+printf '\033]2;'
+repeat 600 T
+printf '\007'
+printf 'A'
+
+# a long title closed by ESC backslash, whose ESC may fall on a read
+# boundary
+printf '\033]2;'
+repeat 600 U
+printf '\033\\'
+printf 'B'
+
+# an OSC longer than the 4096 codepoint buffer is discarded up to its ST
+printf '\033]2;'
+repeat 4100 V
+printf '\007X'
+printf 'C'
diff --git a/tests/tests.results b/tests/tests.results
index 31e72825..bc9c5d4c 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -209,3 +209,4 @@ dcs-long.sh 56028fb44070f1bf64f323f751f0d79a
 backlog-long-line.sh f4423fa1c7069b9bf8a62045cc97dda3
 ty-escape-long.sh 83d61b472b818eb3d699021e14e45452
 csi-c0.sh 68f5a8be4feacac8b7b8d4d5b9b026af
+osc-long.sh a94cb70dd58d07f52bbdf0cc5e7b95e1

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

Reply via email to