[pango] coretext: silently fail on invalid UTF8 instead of crashing



commit fa4cd1a232529898a616e86ab89965d5ffc52347
Author: Kristian Rietveld <kris lanedo com>
Date:   Mon Aug 27 09:37:11 2012 +0200

    coretext: silently fail on invalid UTF8 instead of crashing
    
    When an attempt is made to create a CFString with a C string containing
    invalid UTF8, the call returns NULL. We now check this return value
    and silently fail instead of continuing and reading from a NULL
    pointer.

 modules/basic/basic-coretext.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/modules/basic/basic-coretext.c b/modules/basic/basic-coretext.c
index edbef40..5d0eb07 100644
--- a/modules/basic/basic-coretext.c
+++ b/modules/basic/basic-coretext.c
@@ -174,7 +174,7 @@ run_iterator_get_index (struct RunIterator *iter)
   return iter->current_indices[iter->ct_i];
 }
 
-static void
+static gboolean
 run_iterator_create (struct RunIterator *iter,
                      const char         *text,
                      const gint          length,
@@ -213,6 +213,12 @@ run_iterator_create (struct RunIterator *iter,
                                           kCFStringEncodingUTF8);
   g_free (copy);
 
+  if (!iter->cstr)
+    /* Creating a CFString can fail if the input string does not
+     * adhere to the specified encoding (i.e. it contains invalid UTF8).
+     */
+    return FALSE;
+
   attstr = CFAttributedStringCreate (kCFAllocatorDefault,
                                      iter->cstr,
                                      attributes);
@@ -234,6 +240,8 @@ run_iterator_create (struct RunIterator *iter,
     run_iterator_set_current_run (iter, 0);
   else
     iter->total_ct_i = -1;
+
+  return TRUE;
 }
 
 static void
@@ -313,7 +321,8 @@ create_core_text_glyph_list (const char *text,
   GSList *glyph_list = NULL;
   struct RunIterator riter;
 
-  run_iterator_create (&riter, text, length, ctfont);
+  if (!run_iterator_create (&riter, text, length, ctfont))
+    return NULL;
 
   while (!run_iterator_at_end (&riter))
     {
@@ -388,6 +397,8 @@ basic_engine_shape (PangoEngineShape    *engine,
 
   glyph_list = create_core_text_glyph_list (text, length,
                                             pango_core_text_font_get_ctfont (cfont));
+  if (!glyph_list)
+    return;
 
   /* Translate the glyph list to a PangoGlyphString */
   n_chars = g_utf8_strlen (text, length);



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