From: Dirk-Jan C. Binnema Date: Sun, 8 Jul 2007 10:32:26 +0000 (+0000) Subject: * include artificial breakpoints in very long (>256 chars) lines; this will make... X-Git-Tag: git_migration_finished~2911 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=95a844036e2eb46e1c59838899e9334d236181a3 * include artificial breakpoints in very long (>256 chars) lines; this will make sure the regexp parsing is not DoS'ing modest in some pathological cases. the problem was that we do a text->html conversion for showing messages, and run some regexps to hyperlinkify things that look like email addresses etc., when lines are really long, this takes a *lot* of time. Fixes: NB#62530 pmo-trunk-r2627 --- diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index 52d9ecf..3c32ada 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -300,6 +300,7 @@ modest_text_utils_convert_buffer_to_html (GString *html, const gchar *data) guint i; gboolean space_seen = FALSE; gsize len; + guint break_dist = 0; /* distance since last break point */ len = strlen (data); @@ -312,6 +313,15 @@ modest_text_utils_convert_buffer_to_html (GString *html, const gchar *data) space_seen = FALSE; } + /* we artificially insert a breakpoint (newline) + * after 256, to make sure our lines are not so long + * they will DOS the regexping later + */ + if (++break_dist == 256) { + g_string_append_c (html, '\n'); + break_dist = 0; + } + switch (kar) { case 0: break; /* ignore embedded \0s */ case '<' : g_string_append (html, "<"); break; @@ -319,9 +329,10 @@ modest_text_utils_convert_buffer_to_html (GString *html, const gchar *data) case '&' : g_string_append (html, "&"); break; case '"' : g_string_append (html, """); break; case '\'' : g_string_append (html, "'"); break; - case '\n' : g_string_append (html, "
\n"); break; - case '\t' : g_string_append (html, "    "); break; /* note the space at the end*/ + case '\n' : g_string_append (html, "
\n"); break_dist= 0; break; + case '\t' : g_string_append (html, "    "); break_dist=0; break; /* note the space at the end*/ case ' ': + break_dist = 0; if (space_seen) { /* second space in a row */ g_string_append (html, "  "); space_seen = FALSE;