From 7a85663c2bd9a0e553bf6c02ca92f7c645bed915 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 7 Jul 2023 19:21:18 -0600 Subject: [PATCH] Revert "[sanitize] Add "fastpath" for ArrayOfOffset16To<> objects with max size" This reverts commit 10f8556c73f3cf231c6b5a900a6a1903f9516f90. This was, unfortunately, wrong :(. --- src/OT/Layout/GSUB/Ligature.hh | 5 +---- src/hb-machinery.hh | 4 ---- src/hb-null.hh | 9 --------- src/hb-open-type.hh | 25 ------------------------- src/hb-ot-layout-gsubgpos.hh | 12 ++---------- 5 files changed, 3 insertions(+), 52 deletions(-) diff --git a/src/OT/Layout/GSUB/Ligature.hh b/src/OT/Layout/GSUB/Ligature.hh index 40b7ca50c..402ed12ae 100644 --- a/src/OT/Layout/GSUB/Ligature.hh +++ b/src/OT/Layout/GSUB/Ligature.hh @@ -19,14 +19,11 @@ struct Ligature * in writing direction */ public: DEFINE_SIZE_ARRAY (Types::size + 2, component); - DEFINE_SIZE_MAX (Types::size + 2 + HB_MAX_CONTEXT_LENGTH * Types::HBGlyphID::static_size); bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (ligGlyph.sanitize (c) && - component.sanitize (c) && - component.lenP1 <= HB_MAX_CONTEXT_LENGTH); + return_trace (ligGlyph.sanitize (c) && component.sanitize (c)); } bool intersects (const hb_set_t *glyphs) const diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index cde1e99d6..ecff94f1b 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -131,10 +131,6 @@ static inline Type& StructAfter(TObject &X) unsigned int get_size () const { return (size - (array).min_size + (array).get_size ()); } \ DEFINE_SIZE_ARRAY(size, array) -#define DEFINE_SIZE_MAX(size) \ - DEFINE_INSTANCE_ASSERTION (sizeof (*this) <= (size)) \ - static constexpr unsigned max_size = (size) - /* diff --git a/src/hb-null.hh b/src/hb-null.hh index 298251628..024089397 100644 --- a/src/hb-null.hh +++ b/src/hb-null.hh @@ -48,15 +48,6 @@ template using hb_has_min_size = _hb_has_min_size; #define hb_has_min_size(T) hb_has_min_size::value -template -struct _hb_has_max_size : hb_false_type {}; -template -struct _hb_has_max_size> - : hb_true_type {}; -template -using hb_has_max_size = _hb_has_max_size; -#define hb_has_max_size(T) hb_has_max_size::value - template struct _hb_has_null_size : hb_false_type {}; template diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 3fbd6d362..d41e44c99 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -312,8 +312,6 @@ struct _hb_has_null template struct OffsetTo : Offset { - using target_t = Type; - // Make sure Type is not unbounded; works only for types that are fully defined at OffsetTo time. static_assert (has_null == false || (hb_has_null_size (Type) || !hb_has_min_size (Type)), ""); @@ -714,29 +712,6 @@ struct ArrayOf return_trace (out); } - /* Special-case ArrayOf Offset16To structs with a maximum size. */ - template - bool sanitize (hb_sanitize_context_t *c, const Base *base) const - { - TRACE_SANITIZE (this); - - if (unlikely (!sanitize_shallow (c))) return_trace (false); - - unsigned max_len = 65536 + Type::target_t::max_size; - - if (unlikely (c->check_range_fast (base, max_len))) - return_trace (true); - - unsigned int count = len; - for (unsigned int i = 0; i < count; i++) - if (unlikely (!c->dispatch (arrayZ[i], base))) - return_trace (false); - return_trace (true); - } - template bool sanitize (hb_sanitize_context_t *c, Ts&&... ds) const { diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 8d703a0af..1a9204d9f 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -2014,9 +2014,7 @@ struct Rule lookupCount.sanitize (c) && c->check_range (inputZ.arrayZ, inputZ.item_size * (inputCount ? inputCount - 1 : 0) + - LookupRecord::static_size * lookupCount) && - inputCount <= HB_MAX_CONTEXT_LENGTH && - lookupCount <= HB_MAX_CONTEXT_LENGTH); + LookupRecord::static_size * lookupCount)); } protected: @@ -2032,7 +2030,6 @@ struct Rule * design order */ public: DEFINE_SIZE_ARRAY (4, inputZ); - DEFINE_SIZE_MAX (4 + HB_MAX_CONTEXT_LENGTH * (Types::HBUINT::static_size + LookupRecord::static_size)); }; template @@ -3095,11 +3092,7 @@ struct ChainRule const auto &lookahead = StructAfter (input); if (!lookahead.sanitize (c)) return_trace (false); const auto &lookup = StructAfter (lookahead); - if (!lookup.sanitize (c)) return_trace (false); - return_trace (backtrack.len <= HB_MAX_CONTEXT_LENGTH && - input.lenP1 <= HB_MAX_CONTEXT_LENGTH && - lookahead.len <= HB_MAX_CONTEXT_LENGTH && - lookup.len <= HB_MAX_CONTEXT_LENGTH); + return_trace (lookup.sanitize (c)); } protected: @@ -3118,7 +3111,6 @@ struct ChainRule * design order) */ public: DEFINE_SIZE_MIN (8); - DEFINE_SIZE_MAX (8 + HB_MAX_CONTEXT_LENGTH * (3 * Types::HBUINT::static_size + LookupRecord::static_size)); }; template