[glyf] Add an edge-count limit

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=55246
This commit is contained in:
Behdad Esfahbod 2023-01-20 08:21:43 -07:00
parent 2cfd4133fb
commit d06976e68f
2 changed files with 14 additions and 3 deletions

View File

@ -207,9 +207,14 @@ struct Glyph
bool use_my_metrics = true,
bool phantom_only = false,
hb_array_t<int> coords = hb_array_t<int> (),
unsigned int depth = 0) const
unsigned int depth = 0,
unsigned *edge_count = nullptr) const
{
if (unlikely (depth > HB_MAX_NESTING_LEVEL)) return false;
unsigned stack_edge_count = 0;
if (!edge_count) edge_count = &stack_edge_count;
if (unlikely (*edge_count > HB_GLYF_MAX_EDGE_COUNT)) return false;
(*edge_count)++;
if (!coords)
coords = hb_array (font->coords, font->num_coords);
@ -316,7 +321,8 @@ struct Glyph
use_my_metrics,
phantom_only,
coords,
depth + 1)))
depth + 1,
edge_count)))
return false;
/* Copy phantom points from component if USE_MY_METRICS flag set */
@ -381,7 +387,8 @@ struct Glyph
use_my_metrics,
phantom_only,
coord_setter.get_coords (),
depth + 1)))
depth + 1,
edge_count)))
return false;
/* Apply component transformation */

View File

@ -93,6 +93,10 @@
#define HB_GLYF_MAX_POINTS 10000
#endif
#ifndef HB_GLYF_MAX_EDGE_COUNT
#define HB_GLYF_MAX_EDGE_COUNT 1024
#endif
#ifndef HB_CFF_MAX_OPS
#define HB_CFF_MAX_OPS 10000
#endif