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 12a61871a5ef1a2eab7df0fcf1d0201b3fafe996
Author: Boris Faure <[email protected]>
AuthorDate: Wed Nov 4 22:01:56 2026 +0000
termptyesc: resume an incomplete CSI where its scan stopped
A CSI split across reads was scanned again from its start on each
read, executing its C0 controls again: with \033[1\n\n\n32m read 1
byte at a time, the cursor went down 9 rows instead of 3. The rescan
also made a long CSI quadratic to parse.
The CSI scanner now records how far it got in ty->seq_scanned, for the
next read to resume from there.
tybench sgr corpus: unchanged within the noise.
---
src/bin/termpty.h | 2 ++
src/bin/termptyesc.c | 22 +++++++++++++++++++---
tests/csi-c0.sh | 26 ++++++++++++++++++++++++++
tests/tests.results | 1 +
4 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index 5da25342..dcfd9be5 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -273,6 +273,8 @@ struct tag_Termpty
unsigned int osc_skip_esc : 1; /* and the last codepoint was ESC */
unsigned int dcs_skip : 1; /* discarding a DCS too long for the buffer */
unsigned int apc_skip : 1; /* inside an APC split across reads */
+ /* how far the scan of the incomplete sequence at the head of buf went */
+ unsigned int seq_scanned;
/* bumped on each palette rewrite (OSC 4); scopes the truecolour cache */
unsigned int palette_generation;
struct {
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 6123244d..7a5bf4af 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -3685,14 +3685,27 @@ _handle_xmodkeys(Termpty *ty,
ty->termstate.xmod[resource] = 0;
}
}
+
+/* For a sequence that is not complete yet: the next read resumes its scan
+ * where this one stopped, at cc, rather than rescanning it whole. A scanner
+ * clears ty->seq_scanned as it reads it. */
+static int
+_seq_incomplete(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *cc)
+{
+ ty->seq_scanned = cc - c;
+ return 0;
+}
+
static int
_handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
{
const Eina_Unicode *cc, *be;
Eina_Unicode buf[4096], *b;
+ unsigned int scanned = ty->seq_scanned;
- cc = (Eina_Unicode *)c;
- b = buf;
+ ty->seq_scanned = 0;
+ cc = c + scanned;
+ b = buf + scanned;
be = buf + sizeof(buf) / sizeof(buf[0]);
while ((cc < ce) && (*cc <= '?') && (b < be))
{
@@ -3706,7 +3719,10 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
ERR("csi parsing overflowed, skipping the whole buffer (binary data?)");
return cc - c;
}
- if (cc == ce) return 0;
+ if (cc == ce)
+ return _seq_incomplete(ty, c, cc);
+ if (scanned)
+ memcpy(buf, c, scanned * sizeof(Eina_Unicode));
*b = 0;
be = b;
b = buf;
diff --git a/tests/csi-c0.sh b/tests/csi-c0.sh
new file mode 100644
index 00000000..56749bec
--- /dev/null
+++ b/tests/csi-c0.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+# shellcheck source=tests/utils.sh
+. "$(dirname "$0")/utils.sh"
+
+# C0 controls within a CSI are executed once, wherever the reads split it
+
+# clear screen
+printf '\033[2J'
+
+# move to 0; 0
+printf '\033[0;0H'
+
+# three LFs within a SGR
+printf '\033[1\n\n\n32mA'
+
+# a BS and a HT within a SGR
+printf '\033[\b\t0mB'
+
+# LFs within a CSI longer than a read, ended by a SGR
+printf '\033[3'
+i=0
+while [ $i -lt 64 ]; do
+ printf ';3'
+ i=$((i + 1))
+done
+printf "\n\n1mC"
diff --git a/tests/tests.results b/tests/tests.results
index c191b444..31e72825 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -208,3 +208,4 @@ dcs-cancel.sh 5802db97bcbf6f2ab0d8e49723fcfea8
dcs-long.sh 56028fb44070f1bf64f323f751f0d79a
backlog-long-line.sh f4423fa1c7069b9bf8a62045cc97dda3
ty-escape-long.sh 83d61b472b818eb3d699021e14e45452
+csi-c0.sh 68f5a8be4feacac8b7b8d4d5b9b026af
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.