commit c85f783: [Fix] Fix size calculations when converting from utf16

Vsevolod Stakhov vsevolod at highsecure.ru
Wed Oct 16 12:21:10 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-10-16 13:17:08 +0100
URL: https://github.com/rspamd/rspamd/commit/c85f7833d8eac693b0a67440a19b0c8b66e61b46 (HEAD -> master)

[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) {


More information about the Commits mailing list