From 700af0ab1d8e85f1f191f4b97f3dda456b5a9551 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 12 Feb 2022 21:20:29 +0000 Subject: [PATCH] vim-patch:8.2.4362: :retab may allocate too much memory Problem: :retab may allocate too much memory. Solution: Bail out when allocating more than MAXCOL bytes. https://github.com/vim/vim/commit/33f3c5985491032d5bdfc30e722e85d5a0285e64 --- src/nvim/ex_cmds.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index f6ef259dbd..306da0ec68 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -814,7 +814,11 @@ void ex_retab(exarg_T *eap) // len is actual number of white characters used len = num_spaces + num_tabs; old_len = (long)STRLEN(ptr); - long new_len = old_len - col + start_col + len + 1; + const long new_len = old_len - col + start_col + len + 1; + if (new_len >= MAXCOL) { + emsg(_(e_resulting_text_too_long)); + break; + } new_line = xmalloc(new_len); if (start_col > 0) {