mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-30 18:13:53 +01:00
[gpos] Skip non-increasing Coverage indices in PairPosFormat1::intersects fast path (#6623)
* [gpos] Skip non-increasing Coverage indices in PairPosFormat1::intersects fast path The slow-population fast path of PairPosFormat1_3::intersects() walked the glyph set and indexed pairSet by the Coverage index of each glyph. In a well-formed font those indices increase with glyph id, but a broken Coverage can repeat an index, so one PairSet could be scanned once per glyph, giving quadratic time. Track the last index used and skip any that does not increase (and any NOT_COVERED), following the existing "Broken table. Skip." convention, so each PairSet is scanned at most once. Well-formed fonts are unchanged. Adds a fuzzer regression font. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-6GSU471N. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * [subset] Skip PairPosFormat2 classes outside the class matrix when collecting variation indices collect_pair_variation_indices() added every class returned by the two ClassDefs to class1_set / class2_set without bounding them by class1Count / class2Count. A ClassDef can map glyphs to classes far outside the value matrix, so the collected sets could be enormous and the subsequent nested loop quadratic, although apply() and the serialization loops only ever touch classes inside the matrix. Bound the collected classes by class1Count / class2Count, the same bound the rest of the code already uses. Output is byte-identical; adds a fuzzer regression font. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-C60AYSA3. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
commit
8aa3f2a887
4 files changed
+13
-2
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 ()
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user