Skip to content

Commit fef4ddd

Browse files
committed
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)
1 parent 06b77ef commit fef4ddd

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/libvterm/src/encoding.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@ static void decode_utf8(VTermEncoding *enc UNUSED, void *data_,
4646
return;
4747

4848
else if(c >= 0x20 && c < 0x7f) {
49-
if(data->bytes_remaining)
49+
if(data->bytes_remaining) {
50+
data->bytes_remaining = 0;
5051
cp[(*cpi)++] = UNICODE_INVALID;
51-
52+
if (*cpi >= cplen)
53+
break;
54+
}
5255
cp[(*cpi)++] = c;
5356
#ifdef DEBUG_PRINT_UTF8
5457
printf(" UTF-8 char: U+%04x\n", c);
5558
#endif
56-
data->bytes_remaining = 0;
5759
}
5860

5961
else if(c == 0x7f) /* DEL */

src/libvterm/src/state.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,9 @@ static int on_text(const char bytes[], size_t len, void *user)
248248

249249
VTermPos oldpos = state->pos;
250250

251-
/* We'll have at most len codepoints */
252-
codepoints = vterm_allocator_malloc(state->vt, len * sizeof(uint32_t));
251+
/* We'll have at most len codepoints, plus one from a previous incomplete
252+
* sequence. */
253+
codepoints = vterm_allocator_malloc(state->vt, (len + 1) * sizeof(uint32_t));
253254

254255
encoding =
255256
state->gsingle_set ? &state->encoding[state->gsingle_set] :

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ static char *(features[]) =
771771

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1467,
774776
/**/
775777
1466,
776778
/**/

0 commit comments

Comments
 (0)