diff --git a/src/hb-aat-layout-kerx-table.hh b/src/hb-aat-layout-kerx-table.hh index ccba8fe18..6e9f30073 100644 --- a/src/hb-aat-layout-kerx-table.hh +++ b/src/hb-aat-layout-kerx-table.hh @@ -267,7 +267,7 @@ struct KerxSubTableFormat1 unsigned int kern_idx = Format1EntryT::kernActionIndex (entry); kern_idx = Types::offsetToIndex (kern_idx, &table->machine, kernAction.arrayZ); const FWORD *actions = &kernAction[kern_idx]; - if (!c->sanitizer.check_array (actions, depth * tuple_count)) + if (!c->sanitizer.check_array2 (actions, depth, tuple_count)) { depth = 0; return false; diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index 9e4c16d81..6155c0128 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -298,7 +298,8 @@ struct hb_sanitize_context_t : this->start = this->end = nullptr; } - inline bool check_range (const void *base, unsigned int len) const + inline bool check_range (const void *base, + unsigned int len) const { const char *p = (const char *) base; bool ok = this->start <= p && @@ -316,20 +317,22 @@ struct hb_sanitize_context_t : } template - inline bool check_array (const T *base, unsigned int len, unsigned int record_size = T::static_size) const + inline bool check_array (const T *base, + unsigned int len, + unsigned int record_size = T::static_size) const { - const char *p = (const char *) base; - bool overflows = hb_unsigned_mul_overflows (len, record_size); - unsigned int array_size = record_size * len; - bool ok = !overflows && this->check_range (base, array_size); + return !hb_unsigned_mul_overflows (len, record_size) && + this->check_range (base, len * record_size); + } - DEBUG_MSG_LEVEL (SANITIZE, p, this->debug_depth+1, 0, - "check_array [%p..%p] (%d*%d=%d bytes) in [%p..%p] -> %s", - p, p + (record_size * len), record_size, len, (unsigned int) array_size, - this->start, this->end, - overflows ? "OVERFLOWS" : ok ? "OK" : "OUT-OF-RANGE"); - - return likely (ok); + template + inline bool check_array2 (const T *base, + unsigned int a, + unsigned int b, + unsigned int record_size = T::static_size) const + { + return !hb_unsigned_mul_overflows (a, b) && + this->check_array (base, a * b, record_size); } template