5fabc5
commit 490f8979a260c16b1df055eab386345da18a2d54
5fabc5
Author: Matthias Clasen <mclasen@redhat.com>
5fabc5
Date:   Wed Jul 10 20:26:23 2019 -0400
5fabc5
5fabc5
    bidi: Be safer against bad input
5fabc5
    
5fabc5
    Don't run off the end of an array that we
5fabc5
    allocated to certain length.
5fabc5
    
5fabc5
    Closes: https://gitlab.gnome.org/GNOME/pango/issues/342
5fabc5
5fabc5
diff --git a/pango/pango-bidi-type.c b/pango/pango-bidi-type.c
5fabc5
index 3e46b66c..5c02dbbb 100644
5fabc5
--- a/pango/pango-bidi-type.c
5fabc5
+++ b/pango/pango-bidi-type.c
5fabc5
@@ -181,8 +181,11 @@ pango_log2vis_get_embedding_levels (const gchar    *text,
5fabc5
   for (i = 0, p = text; p < text + length; p = g_utf8_next_char(p), i++)
5fabc5
     {
5fabc5
       gunichar ch = g_utf8_get_char (p);
5fabc5
-      FriBidiCharType char_type;
5fabc5
-      char_type = fribidi_get_bidi_type (ch);
5fabc5
+      FriBidiCharType char_type = fribidi_get_bidi_type (ch);
5fabc5
+
5fabc5
+      if (i == n_chars)
5fabc5
+        break;
5fabc5
+
5fabc5
       bidi_types[i] = char_type;
5fabc5
       ored_types |= char_type;
5fabc5
       if (FRIBIDI_IS_STRONG (char_type))