]> granicus.if.org Git - vim/commitdiff
patch 8.2.2078: illegal memory access when using :print on invalid text v8.2.2078
authorBram Moolenaar <Bram@vim.org>
Wed, 2 Dec 2020 11:37:37 +0000 (12:37 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 2 Dec 2020 11:37:37 +0000 (12:37 +0100)
Problem:    Illegal memory access when using :print on invalid text. (Dhiraj
            Mishra)
Solution:   Check for more composing characters than supported. (closes #7399)

src/message.c
src/testdir/test_utf8.vim
src/version.c

index f8efabc80d6388e42bcc6343486816398b84b6fd..3f6d56e5deebde5302a44444947c52e7d68589f8 100644 (file)
@@ -1859,7 +1859,11 @@ msg_prt_line(char_u *s, int list)
        else if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1)
        {
            col += (*mb_ptr2cells)(s);
-           if (lcs_nbsp != NUL && list
+           if (l >= MB_MAXBYTES)
+           {
+               STRCPY(buf, "¿");
+           }
+           else if (lcs_nbsp != NUL && list
                    && (mb_ptr2char(s) == 160
                        || mb_ptr2char(s) == 0x202f))
            {
index bfb90c1086203be3acf3b0150ab3fda17309bf9a..a5fd4fb89a3e5935bab84abf2043b90164307d89 100644 (file)
@@ -180,4 +180,13 @@ func Test_setcellwidths()
   call assert_fails('call setcellwidths([[0x33, 0x44, 2]])', 'E1114:')
 endfunc
 
+func Test_print_overlong()
+  " Text with more composing characters than MB_MAXBYTES.
+  new
+  call setline(1, 'axxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
+  s/x/\=nr2char(1629)/g
+  print
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 9234d390bf80160567c3d7d857072bec16a15ff1..2eb5de5fca41a02e5a56799075c575d4ac6d0ec6 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2078,
 /**/
     2077,
 /**/