mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-22 15:31:05 +01:00
hb_depend_data_builder_t::add_edge() stored one record per (source, target, feature tag) with no bound. In GSUB a lookup reached by F feature tags multiplies its N*M substitutions by F, so a lookup whose covered glyphs all share one AlternateSet, selected by many feature tags, produces N*M*F edges from a font that grows only with N+M+F. A 5 KB font yields 33M edges and ~1.4 GB of builder memory; COLRv0 overlapping layer slices reach the same sink without any GSUB. The builder also kept walking after fail(), so an allocation failure still cost the full N*M*F iterations. This adds HB_DEPEND_MAX_EDGES (1<<22, about 4M, next to HB_MAX_GRAPH_EDGE_COUNT in hb-limits.hh and overridable the same way; 16x the largest graph in the test corpus) and enforces it in add_edge(), the single choke point every table's extractor stores through, so hb_subset_depend_from_face_or_fail() returns NULL instead of building an unbounded graph. add_edge() and add_gsub_lookup() return early once the builder has failed, and GSUB_accelerator_t::depend()'s lookup loop stops as well, matching the existing !successful checks in the context walkers, so a failed build does bounded work. A regression test builds the fan-out font in memory with hb_face_builder (no binary test font needed) and checks that a 16x16x4 fan-out is recorded in full and that the 256x256x512 one is refused. test-ot-depend and the api suite pass on the ASan experimental build, and the finding's reproducer now returns NULL in ~1 s. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-9IOHFFER. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>