From f0149722e65a5ccc79a7dfadb3144c7632d1180a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 5 Sep 2024 14:16:35 -0700 Subject: [PATCH] terminal: add integrity check for unmarked grapheme cell --- src/terminal/page.zig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/terminal/page.zig b/src/terminal/page.zig index 495eb5680..7231550e7 100644 --- a/src/terminal/page.zig +++ b/src/terminal/page.zig @@ -289,6 +289,7 @@ pub const Page = struct { UnmarkedGraphemeRow, MissingGraphemeData, InvalidGraphemeCount, + UnmarkedGraphemeCell, MissingStyle, UnmarkedStyleRow, MismatchedStyleRef, @@ -368,6 +369,8 @@ pub const Page = struct { var hyperlinks_seen = std.AutoHashMap(hyperlink.Id, usize).init(alloc); defer hyperlinks_seen.deinit(); + const grapheme_count = self.graphemeCount(); + const rows = self.rows.ptr(self.memory)[0..self.size.rows]; for (rows, 0..) |*row, y| { const graphemes_start = graphemes_seen; @@ -385,6 +388,17 @@ pub const Page = struct { }; graphemes_seen += 1; + } else if (grapheme_count > 0) { + // It should not have grapheme data if it isn't marked. + // The grapheme_count check above is just an optimization + // to speed up integrity checks. + if (self.lookupGrapheme(cell) != null) { + log.warn( + "page integrity violation y={} x={} cell not marked as grapheme", + .{ y, x }, + ); + return IntegrityError.UnmarkedGraphemeCell; + } } if (cell.style_id != style.default_id) {