From b2cef8b6650627f65c43029645942d46103a77df Mon Sep 17 00:00:00 2001 From: erw7 Date: Tue, 28 Jul 2020 00:51:41 +0900 Subject: [PATCH] terminal: fix terminal attribute overflow fixes #11548 --- src/nvim/screen.c | 6 +++--- src/nvim/screen.h | 3 +++ src/nvim/terminal.c | 1 + test/functional/terminal/buffer_spec.lua | 9 +++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 4b4b2c416f..05e3d90c8f 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -2692,8 +2692,8 @@ win_line ( off += col; } - // wont highlight after 1024 columns - int term_attrs[1024] = {0}; + // wont highlight after TERM_ATTRS_MAX columns + int term_attrs[TERM_ATTRS_MAX] = { 0 }; if (wp->w_buffer->terminal) { terminal_get_line_attributes(wp->w_buffer->terminal, wp, lnum, term_attrs); extra_check = true; @@ -4030,7 +4030,7 @@ win_line ( int n = wp->w_p_rl ? -1 : 1; while (col >= 0 && col < grid->Columns) { schar_from_ascii(linebuf_char[off], ' '); - linebuf_attr[off] = term_attrs[vcol]; + linebuf_attr[off] = vcol >= TERM_ATTRS_MAX ? 0 : term_attrs[vcol]; off += n; vcol += n; col += n; diff --git a/src/nvim/screen.h b/src/nvim/screen.h index 61ed98247d..754ab06bec 100644 --- a/src/nvim/screen.h +++ b/src/nvim/screen.h @@ -32,6 +32,9 @@ EXTERN ScreenGrid default_grid INIT(= SCREEN_GRID_INIT); #define DEFAULT_GRID_HANDLE 1 // handle for the default_grid +// Maximum columns for terminal highlight attributes +#define TERM_ATTRS_MAX 1024 + /// Status line click definition typedef struct { enum { diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 7609006906..3de6f19cda 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -588,6 +588,7 @@ void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr, return; } + width = MIN(TERM_ATTRS_MAX, width); for (int col = 0; col < width; col++) { VTermScreenCell cell; bool color_valid = fetch_cell(term, row, col, &cell); diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index c6ea0c0e6b..fb6e0d0e94 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -264,3 +264,12 @@ describe('No heap-buffer-overflow when using', function() feed_command('bdelete!') end) end) + +describe('No heap-buffer-overflow when', function() + it('set nowrap and send long line #11548', function() + feed_command('set nowrap') + feed_command('autocmd TermOpen * startinsert') + feed_command('call feedkeys("4000ai\\:terminal!\\")') + eq(2, eval('1+1')) + end) +end)