]> granicus.if.org Git - vim/commitdiff
patch 8.0.1467: libvterm doesn't handle illegal byte sequence correctly v8.0.1467
authorBram Moolenaar <Bram@vim.org>
Sun, 4 Feb 2018 13:49:57 +0000 (14:49 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 4 Feb 2018 13:49:57 +0000 (14:49 +0100)
Problem:    Libvterm doesn't handle illegal byte sequence correctly.
Solution:   After the invalid code check if there is space to store another
            character.  Allocate one more character. (zhykzhykzhyk, closes
            #2614, closes #2613)

src/libvterm/src/encoding.c
src/libvterm/src/state.c
src/version.c

index b37a08c3f1f4042216aeb9cefd8e3d1b2c9293a0..43216e24a6ca5cb81418a5fa21685b3cd95983cd 100644 (file)
@@ -46,14 +46,16 @@ static void decode_utf8(VTermEncoding *enc UNUSED, void *data_,
       return;
 
     else if(c >= 0x20 && c < 0x7f) {
-      if(data->bytes_remaining)
+      if(data->bytes_remaining) {
+        data->bytes_remaining = 0;
         cp[(*cpi)++] = UNICODE_INVALID;
-
+       if (*cpi >= cplen)
+         break;
+      }
       cp[(*cpi)++] = c;
 #ifdef DEBUG_PRINT_UTF8
       printf(" UTF-8 char: U+%04x\n", c);
 #endif
-      data->bytes_remaining = 0;
     }
 
     else if(c == 0x7f) /* DEL */
index 5a6feacb1b5890fdaa7745d23138e744bc476204..32dabeb3480e8f29216ba7f1f15c4ed82911d6f4 100644 (file)
@@ -248,8 +248,9 @@ static int on_text(const char bytes[], size_t len, void *user)
 
   VTermPos oldpos = state->pos;
 
-  /* We'll have at most len codepoints */
-  codepoints = vterm_allocator_malloc(state->vt, len * sizeof(uint32_t));
+  /* We'll have at most len codepoints, plus one from a previous incomplete
+   * sequence. */
+  codepoints = vterm_allocator_malloc(state->vt, (len + 1) * sizeof(uint32_t));
 
   encoding =
     state->gsingle_set     ? &state->encoding[state->gsingle_set] :
index bac652b616d0448ba12c11e0c8cfbe334f0b16df..767a348235cdd5a2abe8b13eea7b80710e5ec8b1 100644 (file)
@@ -771,6 +771,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1467,
 /**/
     1466,
 /**/