diff --git a/src/hb-cairo-utils.cc b/src/hb-cairo-utils.cc index 7b4ccefb6..77b3cb0e8 100644 --- a/src/hb-cairo-utils.cc +++ b/src/hb-cairo-utils.cc @@ -274,7 +274,7 @@ _hb_cairo_normalize_color_line (hb_color_stop_t *stops, *omax = max; } -static void +static bool _hb_cairo_get_color_stops (hb_cairo_context_t *c, hb_color_line_t *color_line, unsigned *count, @@ -282,7 +282,11 @@ _hb_cairo_get_color_stops (hb_cairo_context_t *c, { unsigned len = hb_color_line_get_color_stops (color_line, 0, nullptr, nullptr); if (len > *count) + { *stops = (hb_color_stop_t *) hb_malloc (len * sizeof (hb_color_stop_t)); + if (unlikely (!stops)) + return false; + } hb_color_line_get_color_stops (color_line, 0, &len, *stops); for (unsigned i = 0; i < len; i++) if ((*stops)[i].is_foreground) @@ -299,6 +303,7 @@ _hb_cairo_get_color_stops (hb_cairo_context_t *c, } *count = len; + return true; } void @@ -318,7 +323,8 @@ _hb_cairo_paint_linear_gradient (hb_cairo_context_t *c, float min, max; cairo_pattern_t *pattern; - _hb_cairo_get_color_stops (c, color_line, &len, &stops); + if (unlikely (!_hb_cairo_get_color_stops (c, color_line, &len, &stops))) + return; _hb_cairo_normalize_color_line (stops, len, &min, &max); _hb_cairo_reduce_anchors (x0, y0, x1, y1, x2, y2, &xx0, &yy0, &xx1, &yy1); @@ -365,7 +371,8 @@ _hb_cairo_paint_radial_gradient (hb_cairo_context_t *c, float rr0, rr1; cairo_pattern_t *pattern; - _hb_cairo_get_color_stops (c, color_line, &len, &stops); + if (unlikely (!_hb_cairo_get_color_stops (c, color_line, &len, &stops))) + return; _hb_cairo_normalize_color_line (stops, len, &min, &max); xx0 = x0 + min * (x1 - x0); @@ -626,6 +633,12 @@ _hb_cairo_add_sweep_gradient_patches (hb_color_stop_t *stops, { angles = (float *) hb_malloc (sizeof (float) * n_stops); colors = (hb_cairo_color_t *) hb_malloc (sizeof (hb_cairo_color_t) * n_stops); + if (unlikely (!angles || !colors)) + { + hb_free (angles); + hb_free (colors); + return; + } } for (unsigned i = 0; i < n_stops; i++) @@ -828,7 +841,8 @@ _hb_cairo_paint_sweep_gradient (hb_cairo_context_t *c, float max_x, max_y, radius; cairo_pattern_t *pattern; - _hb_cairo_get_color_stops (c, color_line, &len, &stops); + if (unlikely (!_hb_cairo_get_color_stops (c, color_line, &len, &stops))) + return; hb_qsort (stops, len, sizeof (hb_color_stop_t), _hb_cairo_cmp_color_stop);