To: vim_dev@googlegroups.com Subject: Patch 8.0.1467 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1467 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) Files: src/libvterm/src/encoding.c, src/libvterm/src/state.c *** ../vim-8.0.1466/src/libvterm/src/encoding.c 2017-07-24 23:05:31.164530169 +0200 --- src/libvterm/src/encoding.c 2018-02-04 14:48:09.303922536 +0100 *************** *** 46,59 **** return; else if(c >= 0x20 && c < 0x7f) { ! if(data->bytes_remaining) cp[(*cpi)++] = UNICODE_INVALID; ! 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 */ --- 46,61 ---- return; else if(c >= 0x20 && c < 0x7f) { ! 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 } else if(c == 0x7f) /* DEL */ *** ../vim-8.0.1466/src/libvterm/src/state.c 2017-09-05 23:29:29.025108125 +0200 --- src/libvterm/src/state.c 2018-02-03 13:54:33.156129214 +0100 *************** *** 248,255 **** VTermPos oldpos = state->pos; ! /* We'll have at most len codepoints */ ! codepoints = vterm_allocator_malloc(state->vt, len * sizeof(uint32_t)); encoding = state->gsingle_set ? &state->encoding[state->gsingle_set] : --- 248,256 ---- VTermPos oldpos = state->pos; ! /* 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] : *** ../vim-8.0.1466/src/version.c 2018-02-04 14:32:51.446193935 +0100 --- src/version.c 2018-02-04 14:49:06.347541702 +0100 *************** *** 773,774 **** --- 773,776 ---- { /* Add new patch number below this line */ + /**/ + 1467, /**/ -- Just think of all the things we haven't thought of yet. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///