cmap_accelerator_t::closure_glyphs() in the DMAP path expanded, for
every retained variation selector, all of the selector's Default UVS
ranges and resolved each code point with get_variation_glyph(). Any
number of 11-byte selector records may share one Default UVS table and
a 4-byte range covers 256 code points, so the work was bounded by
selectors x covered code points rather than by the table size: a 223 KB
font with 20000 selectors on one 168-range table drove ~860M lookups
and ~49 s of CPU in hb_subset_plan_create_or_fail().
A default mapping can only ever resolve to the nominal glyph, which the
subset plan already retains with the unicode itself, so the closure only
needs the code points that carry a Non-Default UVS mapping in cmap or
DMAP; get_variation_glyph() still decides which table wins for each.
This is exactly what the non-DMAP path (NonDefaultUVS::closure_glyphs)
already does. A collect_variation_non_default_unicodes() accessor is
added alongside the existing collect_variation_unicodes() chain
(VariationSelectorRecord, CmapSubtableFormat14_15, CmapSubtable,
cmap::accelerator_t) and used from the DMAP closure, so the work is one
lookup per 5-byte mapping visited.
No public API or ABI change; hb_face_collect_variation_unicodes() keeps
expanding Default UVS ranges as before, and fonts without DMAP take the
unchanged first branch. The reproducer's plan drops from ~49 s to 0.01 s
with the same 257-glyph result. The separate, older per-record
DefaultUVS::copy() serialization cost (~5.2 s for this font, independent
of DMAP) is left in place.
Adds test_subset_DMAP_shared_default_uvs to test/api/test-subset-cmap.c.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-8RP452C0.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
When rewriting cmap, the subsetter built one hb_set_t of covered code
points per encoding record. SubtableUnicodesCache keyed those sets by
the record's own offset and collected each with num_glyphs = UINT_MAX,
so a font with many records sharing one full-range format 12 subtable
built one ~1.1M-code-point set per record: ~41 s of CPU, or ~2.1 GB of
memory for a 96 KB input, with nothing but the record count (bounded
only by the sanitizer) limiting the work.
Three changes bound it, all matching how nearby cmap code already works:
1. Key cached_unicodes by record->subtable, so records sharing a
subtable share one set (both set_for overloads).
2. Give the cache a num_glyphs member and collect with it instead of
UINT_MAX, as the cmap accelerator already does for
hb_face_collect_unicodes; cmap::serialize fills it from
plan->source->get_num_glyphs() and create_filled_cache() takes it
as a parameter, passed as face->get_num_glyphs() for
hb_subset_preprocess.
3. Process only the first encoding record of each (platformID,
encodingID) pair in both cmap::serialize and create_filled_cache
(variation-selector records exempt). Lookup already sees one record
per pair and EncodingRecord::copy links later records of a format to
the first serialized subtable, so this bounds both the number of
sets built and the _can_drop walk regardless of how many records a
malformed font repeats, independent of whether they share a subtable.
No public API or ABI change. Output is unchanged for well-formed fonts:
the plan's unicodes are already restricted to gids below num_glyphs, and
valid fonts never repeat a (platformID, encodingID) pair. The attached
reproducer's hostile fonts drop from ~41 s / 2.1 GB to ~0 s / 12 MiB
with byte-identical output.
Adds test_subset_cmap_shared_subtable_many_records and
test_subset_cmap_repeated_encoding_records to
test/api/test-subset-cmap.c.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-FSXRDPBT.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The dense DefaultUVS copy path merged adjacent source ranges without
respecting additionalCount's 8-bit limit. Subsetting 257 consecutive
default UVS mappings could leave only one mapping after count truncation.
Start a new range before the additional count overflows. Exercise cmap
formats 14 and 15 at 1, 255, 256, 257, 512, 513, and 768 mappings, checking
both the retained mapping count and the last variation glyph.
Built with C++11 and ran the complete Meson suite: 279 passed.
Assisted-by: OpenAI Codex
Consult DMAP before cmap for nominal and variation mappings, and combine
their character coverage while retaining DMAP precedence. Reuse the cmap
parser and serializer for DMAP, including effective subsetting closure.
Keep DMAP available independently of beyond-64K support; only cmap format
15 remains conditional.
Tested with the full Meson suite and with an HB_NO_BEYOND_64K build.
Assisted-by: OpenAI Codex <codex@openai.com>
Template the variation-selector structures by glyph-ID width.
Add format 15 lookup, collection, sanitization, and closure.
Add format 15 subsetting.
Prefer format 15 when both variation-selector formats are present.
Assisted-by: OpenAI Codex
cmap14 subsetting code was not considering variation selectors in the input unicode set when deciding which variant glyphs to keep. This updates subsetting to only keeps variant glyphs if their variation selector code point is in the input unicodes set.
For https://github.com/harfbuzz/harfbuzz/issues/4911
NotoColorEmoji.ttf uses two cmap subtables
Format 14 | Platform ID 0 | Platform Encoding ID 5
Format 12 | Platform ID 3 | Platform Encoding ID 10
This combination results in the cmap table being dropped during subsetting despite being valid/required.
Include stdbool.h in hb-setset-test.h instead of in the individual
sources, if it is found; otherwise use a simplistic fallback for it if
it is not found.
Also declare variables at the top of the block, to build on pre-C99
compiliers.