diff --git a/src/OT/Layout/GPOS/PairPosFormat1.hh b/src/OT/Layout/GPOS/PairPosFormat1.hh index 47e80b6bf..26446874f 100644 --- a/src/OT/Layout/GPOS/PairPosFormat1.hh +++ b/src/OT/Layout/GPOS/PairPosFormat1.hh @@ -56,9 +56,17 @@ struct PairPosFormat1_3 if (pairSet.len > glyphs->get_population () * hb_bit_storage ((unsigned) pairSet.len)) { + unsigned next = 0; for (hb_codepoint_t g : glyphs->iter ()) { unsigned i = cov.get_coverage (g); + if (i == NOT_COVERED) continue; + /* Broken table. Skip. Important to avoid DoS. + * Coverage indices must increase with glyph id, as the + * Coverage iterator used below enforces; otherwise one + * PairSet could be scanned once per glyph. */ + if (unlikely (i < next)) continue; + next = i + 1; if ((this+pairSet[i]).intersects (glyphs, valueFormat)) return true; } diff --git a/src/OT/Layout/GPOS/PairPosFormat2.hh b/src/OT/Layout/GPOS/PairPosFormat2.hh index 46ceb984f..15c2ab83b 100644 --- a/src/OT/Layout/GPOS/PairPosFormat2.hh +++ b/src/OT/Layout/GPOS/PairPosFormat2.hh @@ -34,7 +34,9 @@ void collect_pair_variation_indices (hb_collect_variation_indices_context_t *c, else { unsigned klass1 = class_def1.get (cp); - class1_set.add (klass1); + /* Classes outside the matrix have no values; apply() ignores them too. */ + if (klass1 < class1_count) + class1_set.add (klass1); } } @@ -42,7 +44,8 @@ void collect_pair_variation_indices (hb_collect_variation_indices_context_t *c, for (const unsigned cp : + c->glyph_set->iter () | hb_filter (klass2_glyphs)) { unsigned klass2 = class_def2.get (cp); - class2_set.add (klass2); + if (klass2 < class2_count) + class2_set.add (klass2); } if (class1_set.is_empty () diff --git a/test/fuzzing/fonts/gpos-pairpos1-coverage-repeated-index-timeout.ttf b/test/fuzzing/fonts/gpos-pairpos1-coverage-repeated-index-timeout.ttf new file mode 100644 index 000000000..f48901da8 Binary files /dev/null and b/test/fuzzing/fonts/gpos-pairpos1-coverage-repeated-index-timeout.ttf differ diff --git a/test/fuzzing/fonts/gpos-pairpos2-class-outside-matrix-timeout.ttf b/test/fuzzing/fonts/gpos-pairpos2-class-outside-matrix-timeout.ttf new file mode 100644 index 000000000..a2d1b68cb Binary files /dev/null and b/test/fuzzing/fonts/gpos-pairpos2-class-outside-matrix-timeout.ttf differ