Simplify sanitize set_object()

This commit is contained in:
Behdad Esfahbod 2018-11-24 23:34:34 -05:00
parent 3d30972699
commit b3c5affc05
3 changed files with 25 additions and 25 deletions

View File

@ -928,9 +928,9 @@ struct KerxTable
/* See comment in sanitize() for conditional here. */ /* See comment in sanitize() for conditional here. */
if (i < count - 1) if (i < count - 1)
c->sanitizer.set_object (*st); c->sanitizer.set_object (st);
else else
c->sanitizer.reset_object (); c->sanitizer.set_object ();
ret |= st->dispatch (c); ret |= st->dispatch (c);
@ -943,7 +943,7 @@ struct KerxTable
st = &StructAfter<SubTable> (*st); st = &StructAfter<SubTable> (*st);
c->set_lookup_index (c->lookup_index + 1); c->set_lookup_index (c->lookup_index + 1);
} }
c->sanitizer.reset_object (); c->sanitizer.set_object ();
return ret; return ret;
} }
@ -962,7 +962,7 @@ struct KerxTable
unsigned int count = thiz()->tableCount; unsigned int count = thiz()->tableCount;
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
{ {
c->reset_object (); c->set_object ();
if (unlikely (!st->u.header.sanitize (c))) if (unlikely (!st->u.header.sanitize (c)))
return_trace (false); return_trace (false);
/* OpenType kern table has 2-byte subtable lengths. That's limiting. /* OpenType kern table has 2-byte subtable lengths. That's limiting.
@ -973,13 +973,13 @@ struct KerxTable
* have multiple subtables. To handle such fonts, we just ignore * have multiple subtables. To handle such fonts, we just ignore
* the length for the last subtable. */ * the length for the last subtable. */
if (i < count - 1) if (i < count - 1)
c->set_object (*st); c->set_object (st);
if (unlikely (!st->sanitize (c))) if (unlikely (!st->sanitize (c)))
return_trace (false); return_trace (false);
st = &StructAfter<SubTable> (*st); st = &StructAfter<SubTable> (*st);
} }
c->reset_object (); c->set_object ();
return_trace (true); return_trace (true);
} }

View File

@ -1026,7 +1026,7 @@ struct Chain
if (reverse) if (reverse)
c->buffer->reverse (); c->buffer->reverse ();
c->sanitizer.set_object (*subtable); c->sanitizer.set_object (subtable);
subtable->dispatch (c); subtable->dispatch (c);
@ -1041,7 +1041,7 @@ struct Chain
subtable = &StructAfter<ChainSubtable<Types> > (*subtable); subtable = &StructAfter<ChainSubtable<Types> > (*subtable);
c->set_lookup_index (c->lookup_index + 1); c->set_lookup_index (c->lookup_index + 1);
} }
c->sanitizer.reset_object (); c->sanitizer.set_object ();
} }
inline unsigned int get_size (void) const { return length; } inline unsigned int get_size (void) const { return length; }
@ -1061,15 +1061,15 @@ struct Chain
unsigned int count = subtableCount; unsigned int count = subtableCount;
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
{ {
c->reset_object (); c->set_object ();
if (unlikely (!c->check_struct (subtable))) if (unlikely (!c->check_struct (subtable)))
return_trace (false); return_trace (false);
c->set_object (*subtable); c->set_object (subtable);
if (!subtable->sanitize (c)) if (!subtable->sanitize (c))
return_trace (false); return_trace (false);
subtable = &StructAfter<ChainSubtable<Types> > (*subtable); subtable = &StructAfter<ChainSubtable<Types> > (*subtable);
} }
c->reset_object (); c->set_object ();
return_trace (true); return_trace (true);
} }

View File

@ -259,13 +259,20 @@ struct hb_sanitize_context_t :
inline void set_max_ops (int max_ops_) { max_ops = max_ops_; } inline void set_max_ops (int max_ops_) { max_ops = max_ops_; }
template <typename T> struct dummy_get_size_t
inline void set_object (const T& obj) { inline unsigned int get_size (void) const { return 0; } };
{
reset_object ();
const char *obj_start = (const char *) &obj; template <typename T = dummy_get_size_t>
const char *obj_end = (const char *) &obj + obj.get_size (); inline void set_object (const T *obj = nullptr)
{
this->start = this->blob->data;
this->end = this->start + this->blob->length;
assert (this->start <= this->end); /* Must not overflow. */
if (!obj) return;
const char *obj_start = (const char *) obj;
const char *obj_end = (const char *) obj + obj->get_size ();
assert (obj_start <= obj_end); /* Must not overflow. */ assert (obj_start <= obj_end); /* Must not overflow. */
if (unlikely (obj_end < this->start || this->end < obj_start)) if (unlikely (obj_end < this->start || this->end < obj_start))
@ -277,16 +284,9 @@ struct hb_sanitize_context_t :
} }
} }
inline void reset_object (void)
{
this->start = this->blob->data;
this->end = this->start + this->blob->length;
assert (this->start <= this->end); /* Must not overflow. */
}
inline void start_processing (void) inline void start_processing (void)
{ {
reset_object (); set_object ();
this->max_ops = MAX ((unsigned int) (this->end - this->start) * HB_SANITIZE_MAX_OPS_FACTOR, this->max_ops = MAX ((unsigned int) (this->end - this->start) * HB_SANITIZE_MAX_OPS_FACTOR,
(unsigned) HB_SANITIZE_MAX_OPS_MIN); (unsigned) HB_SANITIZE_MAX_OPS_MIN);
this->edit_count = 0; this->edit_count = 0;