summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-07-30 09:05:22 -0400
committerMatthias Clasen <mclasen@redhat.com>2021-07-30 09:05:22 -0400
commit3c35748acccf246e77e3f4279367e51aea5d5b26 (patch)
tree380ddd9c6ab1d7c634d58e63c2abdf4e44e73323
parent43cdd9fbab3ababaae7308feec9e4dabdf8dc3a0 (diff)
downloadpango-bidi-stack-size.tar.gz
bidi: Don't blow the stackbidi-stack-size
Limit stack allocation to a reasonable size, so things don't blow up when somebody hands us a ridiculous-size paragraph.
-rw-r--r--pango/pango-bidi-type.c23
1 files 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;
}