[subset] reuse colrv1 max nesting depth constant for sanitize.

This commit is contained in:
Garret Rieger 2021-11-09 09:13:14 -08:00
parent ace98cc65f
commit 64b29dbd59
2 changed files with 8 additions and 10 deletions

View File

@ -38,8 +38,8 @@
*/
#define HB_OT_TAG_COLR HB_TAG('C','O','L','R')
#ifndef COLRV1_MAX_NESTING_LEVEL
#define COLRV1_MAX_NESTING_LEVEL 100
#ifndef HB_COLRV1_MAX_NESTING_LEVEL
#define HB_COLRV1_MAX_NESTING_LEVEL 100
#endif
#ifndef COLRV1_ENABLE_SUBSETTING
@ -102,7 +102,7 @@ struct hb_colrv1_closure_context_t :
hb_set_t *glyphs_,
hb_set_t *layer_indices_,
hb_set_t *palette_indices_,
unsigned nesting_level_left_ = COLRV1_MAX_NESTING_LEVEL) :
unsigned nesting_level_left_ = HB_COLRV1_MAX_NESTING_LEVEL) :
base (base_),
glyphs (glyphs_),
layer_indices (layer_indices_),
@ -1068,7 +1068,8 @@ struct Paint
{
TRACE_SANITIZE (this);
if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
if (unlikely (!c->check_start_recursion ())) return_trace (c->no_dispatch_return_value ());
if (unlikely (!c->check_start_recursion (HB_COLRV1_MAX_NESTING_LEVEL)))
return_trace (c->no_dispatch_return_value ());
switch (u.format) {
case 1: return_trace (c->end_recursion (c->dispatch (u.paintformat1, std::forward<Ts> (ds)...)));
@ -1103,7 +1104,7 @@ struct Paint
case 30: return_trace (c->end_recursion (c->dispatch (u.paintformat30, std::forward<Ts> (ds)...)));
case 31: return_trace (c->end_recursion (c->dispatch (u.paintformat31, std::forward<Ts> (ds)...)));
case 32: return_trace (c->end_recursion (c->dispatch (u.paintformat32, std::forward<Ts> (ds)...)));
default:return_trace (c->end_recursion (c->default_return_value ()));
default:return_trace (c->end_recursion (c->default_return_value ()));
}
}

View File

@ -116,9 +116,6 @@
#ifndef HB_SANITIZE_MAX_SUBTABLES
#define HB_SANITIZE_MAX_SUBTABLES 0x4000
#endif
#ifndef HB_SANITIZE_MAX_DEPTH
#define HB_SANITIZE_MAX_DEPTH 2500
#endif
struct hb_sanitize_context_t :
hb_dispatch_context_t<hb_sanitize_context_t, bool, HB_DEBUG_SANITIZE>
@ -283,9 +280,9 @@ struct hb_sanitize_context_t :
return this->check_range (base, a, b, hb_static_size (T));
}
bool check_start_recursion ()
bool check_start_recursion (int max_depth)
{
if (unlikely (recursion_depth >= HB_SANITIZE_MAX_DEPTH)) return false;
if (unlikely (recursion_depth >= max_depth)) return false;
return ++recursion_depth;
}