From: Behdad Esfahbod Date: Tue, 4 Aug 2009 06:09:34 +0000 (-0400) Subject: [HB] More sanitize() X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cd3827ee567612c5500206b62840702fc956e0f5;p=platform%2Fupstream%2FlibHarfBuzzSharp.git [HB] More sanitize() --- diff --git a/src/hb-open-file-private.hh b/src/hb-open-file-private.hh index c06bb88..50b9bc2 100644 --- a/src/hb-open-file-private.hh +++ b/src/hb-open-file-private.hh @@ -85,7 +85,7 @@ struct TTCHeader { friend struct OpenTypeFontFile; - STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION (TTCHeader, 2); + STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION (TTCHeader, 1, 2); private: Tag ttcTag; /* TrueType Collection ID string: 'ttcf' */ diff --git a/src/hb-open-types-private.hh b/src/hb-open-types-private.hh index a8549e2..3d57122 100644 --- a/src/hb-open-types-private.hh +++ b/src/hb-open-types-private.hh @@ -60,6 +60,7 @@ struct _hb_sanitize_context_t #define SANITIZE_THIS(X) HB_LIKELY ((X).sanitize (SANITIZE_ARG, (const char *) this)) #define SANITIZE_THIS2(X,Y) SANITIZE_THIS (X) && SANITIZE_THIS (Y) +#define SANITIZE_THIS3(X,Y,Z) SANITIZE_THIS (X) && SANITIZE_THIS (Y) && SANITIZE_THIS(Z) #define SANITIZE_SELF() SANITIZE_OBJ (*this) #define SANITIZE_OBJ(X) SANITIZE_MEM(&(X), sizeof (X)) @@ -205,12 +206,12 @@ struct Null \ return *(const Type*)data; \ } /* Like get_for_data(), but checks major version first. */ -#define STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION(Type, Major) \ +#define STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION(Type, MajorMin, MajorMax) \ static inline const Type& get_for_data (const char *data) \ { \ if (HB_UNLIKELY (data == NULL)) return Null(Type); \ const Type& t = *(const Type*)data; \ - if (HB_UNLIKELY (!t.version.major || t.version.major > Major)) return Null(Type); \ + if (HB_UNLIKELY (t.version.major < MajorMin || t.version.major > MajorMax)) return Null(Type); \ return t; \ } @@ -348,6 +349,10 @@ struct FixedVersion { inline operator uint32_t (void) const { return (major << 16) + minor; } + inline bool sanitize (SANITIZE_ARG_DEF) { + return SANITIZE_SELF (); + } + USHORT major; USHORT minor; }; @@ -371,12 +376,11 @@ struct ArrayOf inline bool sanitize (SANITIZE_ARG_DEF) { if (!(SANITIZE (len) && SANITIZE_GET_SIZE())) return false; - /* For non-offset types, this shouldn't be needed + /* XXX For non-recursive types, this is too much overhead */ unsigned int count = len; for (unsigned int i = 0; i < count; i++) if (!SANITIZE (array[i])) return false; - */ } USHORT len; diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index eaa406b..596acd6 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -46,6 +46,12 @@ template struct Record { + inline bool sanitize (SANITIZE_ARG_DEF, const char *base) { + /* Note: Doesn't sanitize referenced object */ + /* Only accept ASCII-visible tags (mind DEL) */ + return (tag & 0x80808080) == 0 && offset.sanitize (SANITIZE_ARG, base); + } + Tag tag; /* 4-byte Tag identifier */ OffsetTo offset; /* Offset from beginning of object holding @@ -53,7 +59,19 @@ struct Record }; template -struct RecordListOf : ArrayOf > +struct RecordArrayOf : ArrayOf > +{ + inline bool sanitize (SANITIZE_ARG_DEF, const char *base) { + if (!(SANITIZE (this->len) && SANITIZE_GET_SIZE())) return false; + unsigned int count = this->len; + for (unsigned int i = 0; i < count; i++) + if (!SANITIZE_THIS (this->array[i])) + return false; + } +}; + +template +struct RecordListOf : RecordArrayOf { inline const Type& operator [] (unsigned int i) const { @@ -65,18 +83,16 @@ struct RecordListOf : ArrayOf > if (HB_UNLIKELY (i >= this->len)) return Null(Tag); return this->array[i].tag; } + + inline bool sanitize (SANITIZE_ARG_DEF) { + return RecordArrayOf::sanitize (SANITIZE_ARG, (const char *) this); + } }; struct Script; -typedef Record