summaryrefslogtreecommitdiff
path: root/src/libvterm/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-02-04 14:49:57 +0100
committerBram Moolenaar <Bram@vim.org>2018-02-04 14:49:57 +0100
commitfef4ddd5eb8816a6607a624aa401bcfa71a63def (patch)
treee5c631418b3d9826cb69b0feee3ac8e280b284a0 /src/libvterm/src
parent06b77ef69f252e1ba8a2136dcbed6622bc2371bb (diff)
downloadvim-git-fef4ddd5eb8816a6607a624aa401bcfa71a63def.tar.gz
patch 8.0.1467: libvterm doesn't handle illegal byte sequence correctlyv8.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)
Diffstat (limited to 'src/libvterm/src')
-rw-r--r--src/libvterm/src/encoding.c8
-rw-r--r--src/libvterm/src/state.c5
2 files changed, 8 insertions, 5 deletions
diff --git a/src/libvterm/src/encoding.c b/src/libvterm/src/encoding.c
index b37a08c3f..43216e24a 100644
--- a/src/libvterm/src/encoding.c
+++ b/src/libvterm/src/encoding.c
@@ -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 */
diff --git a/src/libvterm/src/state.c b/src/libvterm/src/state.c
index 5a6feacb1..32dabeb34 100644
--- a/src/libvterm/src/state.c
+++ b/src/libvterm/src/state.c
@@ -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] :