a73x

124fa6a4

Handle color-only render cells safely

a73x   2026-04-09 06:01

Commit message
Handle color-only render cells safely

src/vt.zig
Old New
@@ -187,10 +187,7 @@ pub const Terminal = struct {
187 self: *const Terminal, 187 self: *const Terminal,
188 cell: ghostty_vt.RenderState.Cell, 188 cell: ghostty_vt.RenderState.Cell,
189 ) CellColors { 189 ) CellColors {
190 const style: ghostty_vt.Style = switch (cell.raw.content_tag) { 190 const style: ghostty_vt.Style = if (cell.raw.style_id != 0) cell.style else .{};
191 .bg_color_palette, .bg_color_rgb => cell.style,
192 else => if (cell.raw.style_id != 0) cell.style else .{},
193 };
194 const colors = self.render_state.colors; 191 const colors = self.render_state.colors;
195 const fg = style.fg(.{ 192 const fg = style.fg(.{
196 .default = colors.foreground, 193 .default = colors.foreground,
@@ -357,6 +354,24 @@ test "Terminal applies OSC 11 background color updates" {
357 ); 354 );
358 } 355 }
359 356
357 test "Terminal resolves color-only cells without reading undefined style state" {
358 var term = try Terminal.init(std.testing.allocator, .{
359 .cols = 80,
360 .rows = 24,
361 });
362 defer term.deinit();
363
364 term.write("\x1b[44m\x1b[K");
365 try term.snapshot();
366
367 const cell = term.render_state.row_data.get(0).cells.get(0);
368 const colors = term.cellColors(cell);
369 const palette = term.render_state.colors.palette;
370
371 try std.testing.expectEqualDeep(rgbToFloat4(term.render_state.colors.foreground), colors.fg);
372 try std.testing.expectEqualDeep(rgbToFloat4(palette[4]), colors.bg);
373 }
374
360 test "Terminal title callback fires on OSC 2" { 375 test "Terminal title callback fires on OSC 2" {
361 var term = try Terminal.init(std.testing.allocator, .{ 376 var term = try Terminal.init(std.testing.allocator, .{
362 .cols = 80, 377 .cols = 80,