[pango/bidi-stack-size: 11/11] bidi: Don't blow the stack




commit 3c35748acccf246e77e3f4279367e51aea5d5b26
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jul 30 09:05:22 2021 -0400

    bidi: Don't blow the stack
    
    Limit stack allocation to a reasonable size, so things
    don't blow up when somebody hands us a ridiculous-size
    paragraph.

 pango/pango-bidi-type.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/pango/pango-bidi-type.c b/pango/pango-bidi-type.c
index 8d4fb852..4975bfd7 100644
--- a/pango/pango-bidi-type.c
+++ b/pango/pango-bidi-type.c
@@ -177,10 +177,21 @@ log2vis_get_embedding_levels (const gchar    *text,
   g_assert (length >= 0);
   g_assert (n_chars >= 0);
 
-  bidi_types = g_alloca (sizeof (FriBidiCharType) * n_chars);
+  if (n_chars < 4096)
+    {
+      bidi_types = g_alloca (sizeof (FriBidiCharType) * n_chars);
+#ifdef USE_FRIBIDI_EX_API
+      bracket_types = g_alloca (sizeof (FriBidiBracketType) * n_chars);
+#endif
+    }
+  else
+    {
+      g_print ("n_chars is %d\n", n_chars);
+      bidi_types = g_new (FriBidiCharType, n_chars);
 #ifdef USE_FRIBIDI_EX_API
-  bracket_types = g_alloca (sizeof (FriBidiBracketType) * n_chars);
+      bracket_types = g_new (FriBidiBracketType, n_chars);
 #endif
+    }
 
   for (i = 0, p = text; p < text + length; p = g_utf8_next_char (p), i++)
     {
@@ -272,6 +283,14 @@ log2vis_get_embedding_levels (const gchar    *text,
 
 resolved:
 
+  if (n_chars >= 4096)
+    {
+      g_free (bidi_types);
+#ifdef USE_FRIBIDI_EX_API
+      g_free (bracket_types);
+#endif
+    }
+
   *pbase_dir = (fribidi_base_dir == FRIBIDI_PAR_LTR) ?  PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL;
 }
 


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