terminal: add integrity check for unmarked grapheme cell

This commit is contained in:
Mitchell Hashimoto
2024-09-05 14:16:35 -07:00
parent a3aa5463a1
commit f0149722e6

View File

@ -289,6 +289,7 @@ pub const Page = struct {
UnmarkedGraphemeRow, UnmarkedGraphemeRow,
MissingGraphemeData, MissingGraphemeData,
InvalidGraphemeCount, InvalidGraphemeCount,
UnmarkedGraphemeCell,
MissingStyle, MissingStyle,
UnmarkedStyleRow, UnmarkedStyleRow,
MismatchedStyleRef, MismatchedStyleRef,
@ -368,6 +369,8 @@ pub const Page = struct {
var hyperlinks_seen = std.AutoHashMap(hyperlink.Id, usize).init(alloc); var hyperlinks_seen = std.AutoHashMap(hyperlink.Id, usize).init(alloc);
defer hyperlinks_seen.deinit(); defer hyperlinks_seen.deinit();
const grapheme_count = self.graphemeCount();
const rows = self.rows.ptr(self.memory)[0..self.size.rows]; const rows = self.rows.ptr(self.memory)[0..self.size.rows];
for (rows, 0..) |*row, y| { for (rows, 0..) |*row, y| {
const graphemes_start = graphemes_seen; const graphemes_start = graphemes_seen;
@ -385,6 +388,17 @@ pub const Page = struct {
}; };
graphemes_seen += 1; 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) { if (cell.style_id != style.default_id) {