From d67025705f0c4993cdd756bc47d942e14ceed0a1 Mon Sep 17 00:00:00 2001
From: Garret Rieger <grieger@google.com>
Date: Fri, 10 Dec 2021 13:52:05 -0800
Subject: [PATCH] [subset] reset the visited lookup count before each closure
 iteration.

---
 src/hb-ot-layout-gsubgpos.hh | 3 +++
 src/hb-ot-layout.cc          | 1 +
 2 files changed, 4 insertions(+)

diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh
index 537df5aee..46f55315f 100644
--- a/src/hb-ot-layout-gsubgpos.hh
+++ b/src/hb-ot-layout-gsubgpos.hh
@@ -81,6 +81,9 @@ struct hb_closure_context_t :
     nesting_level_left++;
   }
 
+  void reset_lookup_visit_count ()
+  { lookup_count = 0; }
+
   bool lookup_limit_exceeded ()
   { return lookup_count > HB_MAX_LOOKUP_VISIT_COUNT; }
 
diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc
index 4e1d23eba..60733648c 100644
--- a/src/hb-ot-layout.cc
+++ b/src/hb-ot-layout.cc
@@ -1530,6 +1530,7 @@ hb_ot_layout_lookups_substitute_closure (hb_face_t      *face,
   unsigned int glyphs_length;
   do
   {
+    c.reset_lookup_visit_count ();
     glyphs_length = glyphs->get_population ();
     if (lookups)
     {