Revert "[sanitize] Remove now-unused set_object() machinery"

This reverts commit bbdb6edb3e.
This commit is contained in:
Behdad Esfahbod 2018-11-24 22:16:47 -05:00
parent 248ce22857
commit 9eeebd8dde
1 changed files with 24 additions and 1 deletions

View File

@ -259,11 +259,34 @@ 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_; }
inline void start_processing (void) template <typename T>
inline void set_object (const T& obj)
{
reset_object ();
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))
this->start = this->end = nullptr;
else
{
this->start = MAX (this->start, obj_start);
this->end = MIN (this->end , obj_end );
}
}
inline void reset_object (void)
{ {
this->start = this->blob->data; this->start = this->blob->data;
this->end = this->start + this->blob->length; this->end = this->start + this->blob->length;
assert (this->start <= this->end); /* Must not overflow. */ assert (this->start <= this->end); /* Must not overflow. */
}
inline void start_processing (void)
{
reset_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;