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 0d1f452dc7c29f83dba898e1c2b299b57928ae23
Author: Boris Faure <[email protected]>
AuthorDate: Wed Nov 11 19:35:48 2026 +0000
termpty: shift the cells of a row with one memmove
Insert mode, ICH, DCH, DECIC, DECDC and DECFI moved the rest of a row
one TERMPTY_CELL_COPY() at a time, a call and a reference check per
cell. Under IRM that is paid for every character typed, and the fuzzers
found inputs spending seconds there.
TERMPTY_CELL_MOVE() moves the run with one memmove. Its references are
updated before the move, from the cells as they were, which is what the
per-cell loops saw too; blocks are walked in the direction of the move
so that a one-cell block is not freed in between.
---
src/bin/termpty.h | 51 ++++++++++++++++++++++++++++-----
src/bin/termptyesc.c | 79 ++++++++++++++++++++++++----------------------------
src/bin/termptyops.c | 11 ++++----
3 files changed, 86 insertions(+), 55 deletions(-)
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index f35325a6..ce8ebacf 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -476,6 +476,14 @@ do { \
memcpy(Tdst, Tsrc, N * sizeof(Termcell)); \
} while (0)
+/* As TERMPTY_CELL_COPY(), for ranges of one row that may overlap */
+#define TERMPTY_CELL_MOVE(Tpty, Tsrc, Tdst, N) \
+do { \
+ if (EINA_UNLIKELY(((Tpty)->hl.size != 0) || ((Tpty)->block.blocks))) \
+ termpty_cells_move_refs(Tpty, Tsrc, Tdst, N); \
+ memmove(Tdst, Tsrc, (N) * sizeof(Termcell)); \
+} while (0)
+
static inline void
term_link_refcount_inc(Termpty *ty, uint16_t link_id, uint16_t count)
@@ -497,18 +505,14 @@ term_link_refcount_dec(Termpty *ty, uint16_t link_id, uint16_t count)
term_link_free(ty, link);
}
-/* The block and link references of n cells copied from src over dst.
- * Links are counted per run of one id: a per-cell update chains every
- * cell on the same refcount. */
+/* The link references of n cells copied from src over dst, counted per run
+ * of one id: a per-cell update chains every cell on the same refcount. */
static inline void
-termpty_cells_copy_refs(Termpty *ty, const Termcell *src, const Termcell *dst,
+termpty_cells_link_refs(Termpty *ty, const Termcell *src, const Termcell *dst,
int n)
{
int i, j;
- if (ty->block.blocks)
- for (i = 0; i < n; i++)
- HANDLE_BLOCK_CODEPOINT_OVERWRITE(ty, dst[i].codepoint, src[i].codepoint);
if (ty->hl.size == 0)
return;
for (i = 0; i < n; i = j)
@@ -533,6 +537,39 @@ termpty_cells_copy_refs(Termpty *ty, const Termcell *src, const Termcell *dst,
}
}
+/* The block and link references of n cells copied from src over dst. */
+static inline void
+termpty_cells_copy_refs(Termpty *ty, const Termcell *src, const Termcell *dst,
+ int n)
+{
+ int i;
+
+ if (ty->block.blocks)
+ for (i = 0; i < n; i++)
+ HANDLE_BLOCK_CODEPOINT_OVERWRITE(ty, dst[i].codepoint, src[i].codepoint);
+ termpty_cells_link_refs(ty, src, dst, n);
+}
+
+/* As termpty_cells_copy_refs(), for overlapping ranges: blocks are walked
+ * so that a cell gains its new reference before losing its old one. */
+static inline void
+termpty_cells_move_refs(Termpty *ty, const Termcell *src, const Termcell *dst,
+ int n)
+{
+ int i;
+
+ if (ty->block.blocks)
+ {
+ if (dst > src)
+ for (i = n - 1; i >= 0; i--)
+ HANDLE_BLOCK_CODEPOINT_OVERWRITE(ty, dst[i].codepoint, src[i].codepoint);
+ else
+ for (i = 0; i < n; i++)
+ HANDLE_BLOCK_CODEPOINT_OVERWRITE(ty, dst[i].codepoint, src[i].codepoint);
+ }
+ termpty_cells_link_refs(ty, src, dst, n);
+}
+
static inline Eina_Bool
term_link_eq(Termpty *ty, Term_Link *hl, uint16_t link_id)
{
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index e2cad516..1c5f5e89 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -1605,19 +1605,20 @@ _handle_esc_csi_dch(Termpty *ty, Eina_Unicode **ptr)
}
TERMPTY_RESTRICT_FIELD(arg, 1, max + 1);
lim = max - arg;
- for (x = ty->cursor_state.cx; x < max; x++)
+ x = ty->cursor_state.cx;
+ if (x < lim)
{
- if (x < lim)
- TERMPTY_CELL_COPY(ty, &(cells[x + arg]), &(cells[x]), 1);
- else
- {
- cells[x].codepoint = ' ';
- if (EINA_UNLIKELY(cells[x].att.link_id))
- term_link_refcount_dec(ty, cells[x].att.link_id, 1);
- cells[x].att = ty->termstate.att;
- cells[x].att.link_id = 0;
- cells[x].att.dblwidth = 0;
- }
+ TERMPTY_CELL_MOVE(ty, &(cells[x + arg]), &(cells[x]), lim - x);
+ x = lim;
+ }
+ for (; x < max; x++)
+ {
+ cells[x].codepoint = ' ';
+ if (EINA_UNLIKELY(cells[x].att.link_id))
+ term_link_refcount_dec(ty, cells[x].att.link_id, 1);
+ cells[x].att = ty->termstate.att;
+ cells[x].att.link_id = 0;
+ cells[x].att.dblwidth = 0;
}
}
@@ -2645,14 +2646,11 @@ static void
_cells_insert_blanks(Termpty *ty, Termcell *cells, int x, int max_right,
int n)
{
- int j;
-
if (n > max_right - x)
n = max_right - x;
if (n <= 0)
return;
- for (j = max_right - 1; j >= x + n; j--)
- TERMPTY_CELL_COPY(ty, &(cells[j - n]), &(cells[j]), 1);
+ TERMPTY_CELL_MOVE(ty, &(cells[x]), &(cells[x + n]), max_right - x - n);
termpty_cell_codepoint_att_fill(ty, ' ', ty->termstate.att,
&(cells[x]), n);
}
@@ -2744,19 +2742,20 @@ _handle_esc_csi_decdc(Termpty *ty, Eina_Unicode **b)
int x;
Termcell *cells = &(TERMPTY_SCREEN(ty, 0, y));
- for (x = ty->cursor_state.cx; x < max_x; x++)
+ x = ty->cursor_state.cx;
+ if (x < lim)
{
- if (x < lim)
- TERMPTY_CELL_COPY(ty, &(cells[x + arg]), &(cells[x]), 1);
- else
- {
- cells[x].codepoint = ' ';
- if (EINA_UNLIKELY(cells[x].att.link_id))
- term_link_refcount_dec(ty, cells[x].att.link_id, 1);
- cells[x].att = ty->termstate.att;
- cells[x].att.link_id = 0;
- cells[x].att.dblwidth = 0;
- }
+ TERMPTY_CELL_MOVE(ty, &(cells[x + arg]), &(cells[x]), lim - x);
+ x = lim;
+ }
+ for (; x < max_x; x++)
+ {
+ cells[x].codepoint = ' ';
+ if (EINA_UNLIKELY(cells[x].att.link_id))
+ term_link_refcount_dec(ty, cells[x].att.link_id, 1);
+ cells[x].att = ty->termstate.att;
+ cells[x].att.link_id = 0;
+ cells[x].att.dblwidth = 0;
}
}
}
@@ -6305,20 +6304,16 @@ _handle_decfi(Termpty *ty)
int x;
Termcell *cells = &(TERMPTY_SCREEN(ty, 0, y));
- for (x = ty->termstate.left_margin; x <= max_x; x++)
- {
- if (x < max_x)
- TERMPTY_CELL_COPY(ty, &(cells[x + 1]), &(cells[x]), 1);
- else
- {
- cells[x].codepoint = ' ';
- if (EINA_UNLIKELY(cells[x].att.link_id))
- term_link_refcount_dec(ty, cells[x].att.link_id, 1);
- cells[x].att = ty->termstate.att;
- cells[x].att.link_id = 0;
- cells[x].att.dblwidth = 0;
- }
- }
+ x = ty->termstate.left_margin;
+ if (x > max_x)
+ continue;
+ TERMPTY_CELL_MOVE(ty, &(cells[x + 1]), &(cells[x]), max_x - x);
+ cells[max_x].codepoint = ' ';
+ if (EINA_UNLIKELY(cells[max_x].att.link_id))
+ term_link_refcount_dec(ty, cells[max_x].att.link_id, 1);
+ cells[max_x].att = ty->termstate.att;
+ cells[max_x].att.link_id = 0;
+ cells[max_x].att.dblwidth = 0;
}
}
else
diff --git a/src/bin/termptyops.c b/src/bin/termptyops.c
index 073426ab..0aaec5c6 100644
--- a/src/bin/termptyops.c
+++ b/src/bin/termptyops.c
@@ -341,7 +341,7 @@ termpty_text_append_known_ascii(Termpty *ty, const Eina_Unicode *codepoints,
int len, size_t plain_ascii_len)
{
Termcell *cells;
- int i, j;
+ int i;
int origin = ty->termstate.left_margin;
Eina_Bool fast_ok = _append_fast_ok(ty);
@@ -418,11 +418,10 @@ termpty_text_append_known_ascii(Termpty *ty, const Eina_Unicode *codepoints,
cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy));
wrapped = EINA_TRUE;
}
- if (ty->termstate.insert)
- {
- for (j = max_right-1; j > ty->cursor_state.cx; j--)
- TERMPTY_CELL_COPY(ty, &(cells[j - 1]), &(cells[j]), 1);
- }
+ if (ty->termstate.insert && (ty->cursor_state.cx < max_right - 1))
+ TERMPTY_CELL_MOVE(ty, &(cells[ty->cursor_state.cx]),
+ &(cells[ty->cursor_state.cx + 1]),
+ max_right - 1 - ty->cursor_state.cx);
/* Not on an iteration that just wrapped: max_right was computed above
* from the pre-wrap cursor, and a whole run written against that stale
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.