diff options
author | Kristian Rietveld <kris@lanedo.com> | 2012-08-27 09:37:11 +0200 |
---|---|---|
committer | Kristian Rietveld <kris@lanedo.com> | 2012-08-27 09:37:11 +0200 |
commit | fa4cd1a232529898a616e86ab89965d5ffc52347 (patch) | |
tree | 6ae87afa6f9022fc119f4373a13ee44b4587b4bd /modules | |
parent | d11ed972b60e56a96e8b63b34168911260706d54 (diff) | |
download | pango-fa4cd1a232529898a616e86ab89965d5ffc52347.tar.gz |
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.
Diffstat (limited to 'modules')
-rw-r--r-- | 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 edbef40f..5d0eb074 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); |