[glyf] Use range_checker_t in composite_iter_t

This commit is contained in:
Ebrahim Byagowi 2019-10-12 21:12:19 +03:30
parent 06e35ce052
commit b0b8551afc
2 changed files with 16 additions and 15 deletions

View File

@ -359,9 +359,10 @@ struct glyf
struct composite_iter_t : hb_iter_with_fallback_t<composite_iter_t, const CompositeGlyphChain &>
{
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<CompositeGlyphChain> () != &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<HBUINT16> (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;

View File

@ -80,20 +80,19 @@ struct contour_point_vector_t : hb_vector_t<contour_point_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 <typename T>
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<F2DOT14> {};
@ -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<unsigned int> private_indices;
if (iterator.current_tuple->has_private_points () &&
!GlyphVarData::unpack_points (p, private_indices, checker))