From 4d4e526b5cc703111eb445b7e319a4cd1917489f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 31 Oct 2018 13:19:42 -0700 Subject: [PATCH] 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. --- src/hb-blob.hh | 2 +- src/hb-ot-glyf-table.hh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hb-blob.hh b/src/hb-blob.hh index 26e2dd70a..0181e94a4 100644 --- a/src/hb-blob.hh +++ b/src/hb-blob.hh @@ -60,7 +60,7 @@ struct hb_blob_t template inline const Type* as (void) const { - return unlikely (!data) ? &Null(Type) : reinterpret_cast (data); + return length < Type::min_size ? &Null(Type) : reinterpret_cast (data); } inline hb_bytes_t as_bytes (void) const { diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index 9437a83d8..7bd175e39 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -55,6 +55,7 @@ struct loca protected: UnsizedArrayOf dataZ; /* Location data. */ + public: DEFINE_SIZE_ARRAY (0, dataZ); }; @@ -484,7 +485,7 @@ struct glyf protected: UnsizedArrayOf dataZ; /* Glyphs data. */ - + public: DEFINE_SIZE_ARRAY (0, dataZ); };