patch 8.0.1467: libvterm doesn't handle illegal byte sequence correctly
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)
diff --git a/src/libvterm/src/encoding.c b/src/libvterm/src/encoding.c
index b37a08c..43216e2 100644
--- a/src/libvterm/src/encoding.c
+++ b/src/libvterm/src/encoding.c
@@ -46,14 +46,16 @@
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 5a6feac..32dabeb 100644
--- a/src/libvterm/src/state.c
+++ b/src/libvterm/src/state.c
@@ -248,8 +248,9 @@
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] :
diff --git a/src/version.c b/src/version.c
index bac652b..767a348 100644
--- a/src/version.c
+++ b/src/version.c
@@ -772,6 +772,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1467,
+/**/
1466,
/**/
1465,