From 4202a3cde3b6065124feb7f4c662563de1e08126 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 24 Nov 2018 22:48:34 -0500 Subject: [PATCH] Minor --- src/hb-open-type.hh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 83edc77..8970ec7 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -443,8 +443,17 @@ struct UnsizedOffsetListOf : UnsizedOffsetArrayOf { inline const Type& operator [] (unsigned int i) const { - return this+this->arrayZ[i]; + const OffsetTo *p = &this->arrayZ[i]; + if (unlikely (p < this->arrayZ)) return Null (Type); /* Overflowed. */ + return this+*p; } + inline Type& operator [] (unsigned int i) + { + const OffsetTo *p = &this->arrayZ[i]; + if (unlikely (p < this->arrayZ)) return Crap (Type); /* Overflowed. */ + return this+*p; + } + inline bool sanitize (hb_sanitize_context_t *c, unsigned int count) const { @@ -867,13 +876,15 @@ struct VarSizedBinSearchArrayOf inline const Type& operator [] (unsigned int i) const { - if (unlikely (i >= header.nUnits)) return Null (Type); + if (unlikely (i >= get_length ())) return Null (Type); return StructAtOffset (&bytesZ, i * header.unitSize); } inline Type& operator [] (unsigned int i) { + if (unlikely (i >= get_length ())) return Crap (Type); return StructAtOffset (&bytesZ, i * header.unitSize); } + inline unsigned int get_length (void) const { return header.nUnits; } inline unsigned int get_size (void) const { return header.static_size + header.nUnits * header.unitSize; } @@ -897,7 +908,7 @@ struct VarSizedBinSearchArrayOf { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c))) return_trace (false); - unsigned int count = header.nUnits; + unsigned int count = get_length (); for (unsigned int i = 0; i < count; i++) if (unlikely (!(*this)[i].sanitize (c, base))) return_trace (false); @@ -908,7 +919,7 @@ struct VarSizedBinSearchArrayOf { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c))) return_trace (false); - unsigned int count = header.nUnits; + unsigned int count = get_length (); for (unsigned int i = 0; i < count; i++) if (unlikely (!(*this)[i].sanitize (c, base, user_data))) return_trace (false); @@ -919,7 +930,7 @@ struct VarSizedBinSearchArrayOf inline const Type *bsearch (const T &key) const { unsigned int size = header.unitSize; - int min = 0, max = (int) header.nUnits - 1; + int min = 0, max = (int) get_length () - 1; while (min <= max) { int mid = ((unsigned int) min + (unsigned int) max) / 2; -- 2.7.4