[tracker] Fixes bug #609850 - tracker-store segfault in...



commit e8ba29bdd517fc329b23ad4d61f05f7d80e4a9f0
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Mar 5 18:13:00 2010 +0100

    Fixes bug #609850 - tracker-store segfault in...
    
    unac_string() was passing integers as size_t, corrupting
    memory. Now strip_word() mimics unac_string() avoiding such
    issue.

 src/libtracker-fts/tracker-parser.c |   35 ++++++++++++++++++++++++++++++++++-
 1 files changed, 34 insertions(+), 1 deletions(-)
---
diff --git a/src/libtracker-fts/tracker-parser.c b/src/libtracker-fts/tracker-parser.c
index f48a73c..ba724e2 100644
--- a/src/libtracker-fts/tracker-parser.c
+++ b/src/libtracker-fts/tracker-parser.c
@@ -144,12 +144,45 @@ strip_word (const gchar *str,
             guint32     *len)
 {
 #ifdef HAVE_UNAC
+	GError *error = NULL;
+	gchar *str_utf16;
+	gsize utf16_len, unaccented_len, final_len;
+	gchar *unaccented_str = NULL;
 	gchar *s = NULL;
 
-	if (unac_string ("UTF-8", str, length, &s, (size_t *) len) != 0) {
+	*len = 0;
+
+	/* unac_string() does roughly the same than below, plus it
+	 * corrupts memory in 64bit systems, so avoid it for now.
+	 */
+	str_utf16 = g_convert (str, length, "UTF-16BE", "UTF-8", NULL, &utf16_len, &error);
+
+	if (error) {
+		g_warning ("Could not convert to UTF-16: %s", error->message);
+		g_error_free (error);
+		return NULL;
+	}
+
+	if (unac_string_utf16 (str_utf16, utf16_len,
+	                       &unaccented_str, &unaccented_len) != 0) {
 		g_warning ("UNAC failed to strip accents");
+		g_free (str_utf16);
+		return NULL;
 	}
 
+	g_free (str_utf16);
+
+	s = g_convert (unaccented_str, unaccented_len, "UTF-8", "UTF-16BE", NULL, &final_len, &error);
+	g_free (unaccented_str);
+
+	if (error) {
+		g_warning ("Could not convert back to UTF-8: %s", error->message);
+		g_error_free (error);
+		return NULL;
+	}
+
+	*len = (guint32) final_len;
+
 	return s;
 #else
 	*len = length;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]