From c66ee213b70eb204b750675d60f25549d942d3d7 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Thu, 27 Feb 2020 12:25:01 -0800 Subject: [PATCH] Limit the number of feature indices processed during feature collection. --- src/hb-ot-layout-common.hh | 5 +++++ src/hb-ot-layout.cc | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 3660c2043..fe2c77bb7 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -60,6 +60,11 @@ #define HB_MAX_LANGSYS 2000 #endif +#ifndef HB_MAX_FEATURE_INDICES +#define HB_MAX_FEATURE_INDICES 2000 +#endif + + namespace OT { diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index b169ada0b..bc285295b 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -983,7 +983,7 @@ struct hb_collect_features_context_t hb_set_t *feature_indexes_) : g (get_gsubgpos_table (face, table_tag)), feature_indexes (feature_indexes_), - script_count(0),langsys_count(0) {} + script_count (0),langsys_count (0), feature_index_count (0) {} bool visited (const OT::Script &s) { @@ -1012,6 +1012,12 @@ struct hb_collect_features_context_t return visited (l, visited_langsys); } + bool visited_feature_indices (unsigned count) + { + feature_index_count += count; + return feature_index_count > HB_MAX_FEATURE_INDICES; + } + private: template bool visited (const T &p, hb_set_t &visited_set) @@ -1033,6 +1039,7 @@ struct hb_collect_features_context_t hb_set_t visited_langsys; unsigned int script_count; unsigned int langsys_count; + unsigned int feature_index_count; }; static void @@ -1045,10 +1052,11 @@ langsys_collect_features (hb_collect_features_context_t *c, if (!features) { /* All features. */ - if (l.has_required_feature ()) + if (l.has_required_feature () && !c->visited_feature_indices (1)) c->feature_indexes->add (l.get_required_feature_index ()); - l.add_feature_indexes_to (c->feature_indexes); + if (!c->visited_feature_indices (l.featureIndex.len)) + l.add_feature_indexes_to (c->feature_indexes); } else {