From bdac5f7d5b8a6b68af4a36222efe4255a9968b8e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 27 Feb 2020 21:33:42 +0530 Subject: [PATCH] Add a bounds check in text_for_range() as well --- kitty/screen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kitty/screen.c b/kitty/screen.c index 64a73f599..34b3d25ec 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -1725,7 +1725,7 @@ text_for_range(Screen *self, const Selection *sel, bool insert_newlines) { iteration_data(self, sel, &idata, -self->historybuf->count, false); PyObject *ans = PyTuple_New(idata.y_limit - idata.y); if (!ans) return NULL; - for (int i = 0, y = idata.y; y < idata.y_limit; y++, i++) { + for (int i = 0, y = idata.y; y < idata.y_limit && y < (int)self->lines; y++, i++) { Line *line = range_line_(self, y); XRange xr = xrange_for_iteration(&idata, y, line); char leading_char = (i > 0 && insert_newlines && !line->continued) ? '\n' : 0;