Improve blob->as<>

It's true that blob->as<> should only be called on null or sanitized
data.  But this change is safe, so keep it.
This commit is contained in:
Behdad Esfahbod 2018-10-31 13:19:42 -07:00
parent 5854d3fa25
commit 4d4e526b5c
2 changed files with 3 additions and 2 deletions

View File

@ -60,7 +60,7 @@ struct hb_blob_t
template <typename Type>
inline const Type* as (void) const
{
return unlikely (!data) ? &Null(Type) : reinterpret_cast<const Type *> (data);
return length < Type::min_size ? &Null(Type) : reinterpret_cast<const Type *> (data);
}
inline hb_bytes_t as_bytes (void) const
{

View File

@ -55,6 +55,7 @@ struct loca
protected:
UnsizedArrayOf<HBUINT8> dataZ; /* Location data. */
public:
DEFINE_SIZE_ARRAY (0, dataZ);
};
@ -484,7 +485,7 @@ struct glyf
protected:
UnsizedArrayOf<HBUINT8> dataZ; /* Glyphs data. */
public:
DEFINE_SIZE_ARRAY (0, dataZ);
};