[cairo] Protect against infinite loops

Fixes https://github.com/harfbuzz/harfbuzz/issues/4375

Maybe we should do this in hb-ft and COLR instead?
This commit is contained in:
Behdad Esfahbod committed 2023-08-15 10:21:26 -06:00
1 parent 7d7541e35d
commit 21a894f055
2 files changed
+11

No files matched your search

+3
View File
@@ -30,11 +30,14 @@
#include "hb.hh"
#include "hb-cairo.h"
#include "hb-set.hh"
typedef struct
{
cairo_scaled_font_t *scaled_font;
cairo_t *cr;
hb_set_t current_glyphs;
hb_map_t *color_cache;
} hb_cairo_context_t;
+8
View File
@@ -176,6 +176,11 @@ hb_cairo_paint_color_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED,
hb_cairo_context_t *c = (hb_cairo_context_t *) paint_data;
cairo_t *cr = c->cr;
if (unlikely (c->current_glyphs.has (glyph)))
return true;
c->current_glyphs.add (glyph);
cairo_save (cr);
hb_position_t x_scale, y_scale;
@@ -189,6 +194,8 @@ hb_cairo_paint_color_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED,
cairo_restore (cr);
c->current_glyphs.del (glyph);
return true;
}
@@ -634,6 +641,7 @@ hb_cairo_render_color_glyph (cairo_scaled_font_t *scaled_font,
c.scaled_font = scaled_font;
c.cr = cr;
c.color_cache = (hb_map_t *) cairo_scaled_font_get_user_data (scaled_font, &color_cache_key);
c.current_glyphs.add (glyph);
hb_font_paint_glyph (font, glyph, hb_cairo_paint_get_funcs (), &c, palette, color);