mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-21 06:51:01 +01:00
The kern/kerx accelerator keeps two hb_bit_set_t per subtable and mort/morx keeps one per subtable, all built eagerly when the shape plan is compiled and held for the life of the face. A 14-byte kern format-3 subtable fills both sets with every glyph, so heap use was about 2100x the font size with nothing bounding the subtable count; morx is worse because overlapping chains can claim each other's subtables. A ~560 KB kern font drove shaping one letter to 1.1 GiB. Add HB_AAT_MAX_SUBTABLES (1024) to hb-limits.hh and enforce it in sanitize, the way GSUB/GPOS already bound their subtables via visit_subtables (whose 0x4000 limit is too loose here -- 16383 kern subtables still peak at hundreds of MiB). KerxTable::sanitize() (shared by kerx, OpenType kern and Apple kern) fails when tableCount exceeds the limit, and mortmorx::sanitize() fails once the chains' subtable counts add up past it. Over-limit tables are dropped entirely (the font shapes without kerning/morx); real fonts under test/ declare at most three kern/kerx subtables and one morx chain. Regression test in test/api/test-aat-layout.c builds kern and morx faces with hb_face_builder and checks both sides of the limit. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-5N52Y0UN. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>