From b0b8551afc2ff86d027fdb380210601cb465af41 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Sat, 12 Oct 2019 21:12:19 +0330 Subject: [PATCH] [glyf] Use range_checker_t in composite_iter_t --- src/hb-ot-glyf-table.hh | 12 +++++++----- src/hb-ot-var-gvar-table.hh | 19 +++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index fd54bd396..f5a64b050 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -359,9 +359,10 @@ struct glyf struct composite_iter_t : hb_iter_with_fallback_t { typedef const CompositeGlyphChain *__item_t__; - composite_iter_t (hb_bytes_t glyph_, __item_t__ current_) : glyph (glyph_), current (current_) + composite_iter_t (hb_bytes_t glyph_, __item_t__ current_) : + glyph (glyph_), current (current_), checker (range_checker_t (glyph.arrayZ, glyph.length)) { if (!in_range (current)) current = nullptr; } - composite_iter_t () : glyph (hb_bytes_t ()), current (nullptr) {} + composite_iter_t () : glyph (hb_bytes_t ()), current (nullptr), checker (range_checker_t (nullptr, 0)) {} const CompositeGlyphChain &__item__ () const { return *current; } bool __more__ () const { return current; } @@ -379,13 +380,14 @@ struct glyf bool in_range (const CompositeGlyphChain *composite) const { - return glyph.sub_array ((const char *) composite - (const char *) &glyph, - CompositeGlyphChain::min_size).as () != &Null (CompositeGlyphChain); + return checker.in_range (composite, CompositeGlyphChain::min_size) + && checker.in_range (composite, composite->get_size ()); } private: hb_bytes_t glyph; __item_t__ current; + range_checker_t checker; }; struct Glyph @@ -569,7 +571,7 @@ struct glyf const bool phantom_only=false) const { const HBUINT16 *endPtsOfContours = &StructAfter (header); - range_checker_t checker (bytes.arrayZ, 0, bytes.length); + range_checker_t checker (bytes.arrayZ, bytes.length); int num_contours = header.numberOfContours; if (unlikely (!checker.in_range (&endPtsOfContours[num_contours + 1]))) return false; unsigned int num_points = endPtsOfContours[num_contours - 1] + 1; diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index 510174c35..666b30895 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -80,20 +80,19 @@ struct contour_point_vector_t : hb_vector_t struct range_checker_t { - range_checker_t (const void *table_, unsigned int start_offset_, unsigned int end_offset_) - : table ((const char*) table_), start_offset (start_offset_), end_offset (end_offset_) {} + range_checker_t (const void *data_, unsigned int length_) + : data ((const char *) data_), length (length_) {} template - bool in_range (const T *p) const + bool in_range (const T *p, unsigned int size = T::static_size) const { - return ((const char *) p) >= table + start_offset - && ((const char *) p + T::static_size) <= table + end_offset; + return ((const char *) p) >= data + && ((const char *) p + size) <= data + length; } protected: - const char *table; - const unsigned int start_offset; - const unsigned int end_offset; + const char *data; + const unsigned int length; }; struct Tuple : UnsizedArrayOf {}; @@ -234,7 +233,7 @@ struct GlyphVarData { if (var_data->has_shared_point_numbers ()) { - range_checker_t checker (var_data, 0, length); + range_checker_t checker (var_data, length); const HBUINT8 *base = &(var_data+var_data->data); const HBUINT8 *p = base; if (!unpack_points (p, shared_indices, checker)) return false; @@ -612,7 +611,7 @@ struct gvar if (unlikely (!iterator.in_range (p, length))) return false; - range_checker_t checker (p, 0, length); + range_checker_t checker (p, length); hb_vector_t private_indices; if (iterator.current_tuple->has_private_points () && !GlyphVarData::unpack_points (p, private_indices, checker))