From c85f7833d8eac693b0a67440a19b0c8b66e61b46 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 16 Oct 2019 13:17:08 +0100 Subject: [PATCH] [Fix] Fix size calculations when converting from utf16 --- src/libmime/archives.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libmime/archives.c b/src/libmime/archives.c index cc81326ec..f3ad60067 100644 --- a/src/libmime/archives.c +++ b/src/libmime/archives.c @@ -1439,14 +1439,16 @@ rspamd_7zip_ucs2_to_utf8 (struct rspamd_task *task, const guchar *p, UChar32 wc; UBool is_error = 0; - res = g_string_sized_new ((end - p) + sizeof (wc) * 2 + 1); + res = g_string_sized_new ((end - p) * 1.5 + sizeof (wc) + 1); up = (guint16 *)p; while (src_pos < len) { U16_NEXT (up, src_pos, len, wc); if (wc > 0) { - U8_APPEND (res->str, dest_pos, res->allocated_len, wc, is_error); + U8_APPEND (res->str, dest_pos, + res->allocated_len - 1, + wc, is_error); } if (is_error) { -- 2.39.5