diff --git a/src/hb-aat-layout-kerx-table.hh b/src/hb-aat-layout-kerx-table.hh index fbeb35b0c..33f626c6f 100644 --- a/src/hb-aat-layout-kerx-table.hh +++ b/src/hb-aat-layout-kerx-table.hh @@ -928,9 +928,9 @@ struct KerxTable /* See comment in sanitize() for conditional here. */ if (i < count - 1) - c->sanitizer.set_object (*st); + c->sanitizer.set_object (st); else - c->sanitizer.reset_object (); + c->sanitizer.set_object (); ret |= st->dispatch (c); @@ -943,7 +943,7 @@ struct KerxTable st = &StructAfter (*st); c->set_lookup_index (c->lookup_index + 1); } - c->sanitizer.reset_object (); + c->sanitizer.set_object (); return ret; } @@ -962,7 +962,7 @@ struct KerxTable unsigned int count = thiz()->tableCount; for (unsigned int i = 0; i < count; i++) { - c->reset_object (); + c->set_object (); if (unlikely (!st->u.header.sanitize (c))) return_trace (false); /* 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 * the length for the last subtable. */ if (i < count - 1) - c->set_object (*st); + c->set_object (st); if (unlikely (!st->sanitize (c))) return_trace (false); st = &StructAfter (*st); } - c->reset_object (); + c->set_object (); return_trace (true); } diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index dc406f59f..bc7c3c37b 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -1026,7 +1026,7 @@ struct Chain if (reverse) c->buffer->reverse (); - c->sanitizer.set_object (*subtable); + c->sanitizer.set_object (subtable); subtable->dispatch (c); @@ -1041,7 +1041,7 @@ struct Chain subtable = &StructAfter > (*subtable); 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; } @@ -1061,15 +1061,15 @@ struct Chain unsigned int count = subtableCount; for (unsigned int i = 0; i < count; i++) { - c->reset_object (); + c->set_object (); if (unlikely (!c->check_struct (subtable))) return_trace (false); - c->set_object (*subtable); + c->set_object (subtable); if (!subtable->sanitize (c)) return_trace (false); subtable = &StructAfter > (*subtable); } - c->reset_object (); + c->set_object (); return_trace (true); } diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index edef54053..7457a099e 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -259,13 +259,20 @@ struct hb_sanitize_context_t : inline void set_max_ops (int max_ops_) { max_ops = max_ops_; } - template - inline void set_object (const T& obj) - { - reset_object (); + struct dummy_get_size_t + { inline unsigned int get_size (void) const { return 0; } }; - const char *obj_start = (const char *) &obj; - const char *obj_end = (const char *) &obj + obj.get_size (); + template + 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. */ 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) { - reset_object (); + set_object (); this->max_ops = MAX ((unsigned int) (this->end - this->start) * HB_SANITIZE_MAX_OPS_FACTOR, (unsigned) HB_SANITIZE_MAX_OPS_MIN); this->edit_count = 0;