From 616f1e200a5e4a1c82879d44e939ca57c7a56445 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 5 Apr 2017 21:02:09 +0100 Subject: [PATCH] [Fix] Fix rfc2047 tokenization --- src/libmime/mime_headers.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libmime/mime_headers.c b/src/libmime/mime_headers.c index 5044fc013..b333fcdfe 100644 --- a/src/libmime/mime_headers.c +++ b/src/libmime/mime_headers.c @@ -641,7 +641,7 @@ gchar * rspamd_mime_header_encode (const gchar *in, gsize len) { const gchar *p = in, *end = in + len; - gchar *out, encode_buf[80]; + gchar *out, encode_buf[80 * sizeof (guint32)]; GString *res; gboolean need_encoding = FALSE; @@ -664,12 +664,14 @@ rspamd_mime_header_encode (const gchar *in, gsize len) gint r; const gchar *prev; /* Choose step: =?UTF-8?Q??= should be less than 76 chars */ - const guint step = (76 - 12) / 3 + 1; + guint step = (76 - 12) / 3 + 1; ulen = g_utf8_strlen (in, len); res = g_string_sized_new (len * 2 + 1); pos = 0; prev = in; + /* Adjust chunk size for unicode average length */ + step *= 1.0 * ulen / (gdouble)len; while (pos < ulen) { p = g_utf8_offset_to_pointer (in, pos); -- 2.39.5