]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fix size calculations when converting from utf16
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 16 Oct 2019 12:17:08 +0000 (13:17 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 16 Oct 2019 12:17:08 +0000 (13:17 +0100)
src/libmime/archives.c

index cc81326ec6264b34c814d7bfefcb0cb0cee9e870..f3ad60067f69707fd03321cfed6ed2c522bfd700 100644 (file)
@@ -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) {