diff --git a/kitty/screen.c b/kitty/screen.c index 46441af42..882d600b6 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -1706,10 +1706,13 @@ select_graphic_rendition(Screen *self, int *params, unsigned int count, bool is_ } else { index_type x, num; if (region.top == region.bottom) { - linebuf_init_line(self->linebuf, region.top); - x = MIN(region.left, self->columns - 1); - num = MIN(self->columns - x, region.right - x + 1); - apply_sgr_to_cells(self->linebuf->line->gpu_cells + x, num, params, count, is_group); + if (region.top < self->lines) { + linebuf_init_line(self->linebuf, region.top); + x = MIN(region.left, self->columns - 1); + num = region.right >= x ? region.right - x + 1 : 0; + num = MIN(self->columns - x, num); + apply_sgr_to_cells(self->linebuf->line->gpu_cells + x, num, params, count, is_group); + } } else { for (index_type y = region.top; y < MIN(region.bottom + 1, self->lines); y++) { if (y == region.top) { diff --git a/kitty_tests/parser.py b/kitty_tests/parser.py index bd2353318..8c059b1b7 100644 --- a/kitty_tests/parser.py +++ b/kitty_tests/parser.py @@ -1227,3 +1227,9 @@ class TestParser(BaseTest): line = s.line(y) for x in range(s.columns): self.ae(line.cursor_from(x).fg, (10 << 8 | 1) if x < 1 or x > 2 else (4 << 8) | 1) + # out of range or inverted single line regions must not touch anything + before = [[s.line(y).cursor_from(x).bold for x in range(s.columns)] for y in range(s.lines)] + for seq in ('\033[100;1;100;5;22$r', '\033[99999999;1;99999999;5;22$r', '\033[10;20;10;2;22$r', '\033[3;4;3;2;22$r'): + parse_bytes(s, seq.encode()) + after = [[s.line(y).cursor_from(x).bold for x in range(s.columns)] for y in range(s.lines)] + self.ae(before, after, seq)