From 3e867a056018c507d79396cb5c5b4b8309c609c2 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Fri, 28 May 2021 11:00:37 +0000 Subject: Fix crashes with cut-off fullwidth characters There's a few places in Alacritty where it was assumed that after a WIDE_CHAR cell, there'd always be a WIDE_CHAR_SPACER. However since resizes in the alternate screen buffer do not reflow any content, it's possible to have a WIDE_CHAR without any WIDE_CHAR_SPACER right behind it. This patch changes these instances to be more defensive about accepting potentially unreasonable input data caused by alt screen resizes. Fixes #5185. Fixes #5170. --- alacritty_terminal/src/term/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'alacritty_terminal/src/term/mod.rs') diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs index 2fb4da34..256f2f29 100644 --- a/alacritty_terminal/src/term/mod.rs +++ b/alacritty_terminal/src/term/mod.rs @@ -699,7 +699,9 @@ impl Term { point.column = Column(1); point.line += 1; }, - Direction::Right if flags.contains(Flags::WIDE_CHAR) => point.column += 1, + Direction::Right if flags.contains(Flags::WIDE_CHAR) => { + point.column = min(point.column + 1, self.last_column()); + }, Direction::Left if flags.intersects(Flags::WIDE_CHAR | Flags::WIDE_CHAR_SPACER) => { if flags.contains(Flags::WIDE_CHAR_SPACER) { point.column -= 1; @@ -774,7 +776,7 @@ impl Term { // Remove wide char and spacer. let wide = cursor_cell.flags.contains(Flags::WIDE_CHAR); let point = self.grid.cursor.point; - if wide { + if wide && point.column + 1 < self.columns() { self.grid[point.line][point.column + 1].flags.remove(Flags::WIDE_CHAR_SPACER); } else { self.grid[point.line][point.column - 1].clear_wide(); -- cgit