Fix out of bounds write in single line DECCARA

This commit is contained in:
rudolf-blue 2026-10-08 22:30:07 -04:00
parent e1250cf8fb
commit 3d007dbf9e
2 changed files with 13 additions and 4 deletions

View file

@ -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) {

View file

@ -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)