From 9eeebd8ddedb96c03860ce7eb5500aafa3969d6b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 24 Nov 2018 22:16:47 -0500 Subject: [PATCH] Revert "[sanitize] Remove now-unused set_object() machinery" This reverts commit bbdb6edb3e1cea4c5b7076c4f6b3e6998ae36dae. --- src/hb-machinery.hh | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index 9ca247d90..edef54053 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -259,11 +259,34 @@ struct hb_sanitize_context_t : inline void set_max_ops (int max_ops_) { max_ops = max_ops_; } - inline void start_processing (void) + template + 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->end = this->start + this->blob->length; 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, (unsigned) HB_SANITIZE_MAX_OPS_MIN); this->edit_count = 0;