* [subset] Charge Coverage and ClassDef glyph walks to a work budget
Coverage::subset() expands a format 2 Coverage glyph by glyph, up to
numGlyphs, every time an offset to it is subset, and nothing bounded
that work. A 10-byte range Coverage referenced by 30,000 two-byte
offsets in a subtable listed 8 times costs 1.6e10 iterator steps,
while the sanitizer only bounds work by table bytes; a 60 KB font
keeps hb-subset busy ~50 s. GDEF's MarkGlyphSets reaches the same
walk with no feature or lookup needing to survive planning.
Give hb_subset_context_t a per-table work budget
(HB_BUDGET_SUBSET_TABLE, in the hb_budget_spend() idiom of
hb-limits.hh) with a check_ops() helper that fails the serializer once
exhausted, and charge Coverage::subset() its capped population before
the walk. Charging inside Coverage::subset() covers every caller
(ReverseChainSingleSubst, (Chain)ContextFormat3, GDEF MarkGlyphSets,
...) without touching them. The same unbounded per-reference pattern
in ClassDefFormat1_3 / ClassDefFormat2_4::subset() (the range or
glyphset walk and the glyph_filter count) is charged the same way.
A hostile table that exceeds the budget now fails the subset cleanly
(hb_subset_or_fail returns NULL) in a fraction of a second instead of
succeeding slowly; valid-font output is byte-identical and the
heaviest local table spends a small fraction of the budget.
test_subset_shared_coverage_budget builds the reverse-chaining GSUB in
memory and asserts 256 shared references subset while 2048 fail.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-LLIWV9UK.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [subset] Charge layout glyph walks to the existing subset budget
Drop the separate HB_BUDGET_SUBSET_TABLE budget and the second
hb_subset_context_t field it needed; check_ops() now charges
budget_remaining (HB_BUDGET_SUBSET_GLYF, 1 << 28), the per-table
budget glyf instancing already uses. Both are per-table and shared
across buffer-size retries, and no table spends both.
The larger budget still bounds the attack (fails after 2^28 glyph
steps, ~3 s), so test_subset_shared_coverage_budget now expects the
failure at 8192 shared offsets instead of 2048.
Subsetting all glyphs with --layout-features='*' of Gulzar,
NotoSansKR-VF and GoogleSansFlex-VF keeps GSUB/GPOS/GDEF with output
byte-identical to before; the heaviest table (Gulzar GPOS) spends
~98K units, under 0.04% of the budget. Full meson test: 278 OK.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
* [subset] Keep hinting for fonts that require it
Some legacy fonts have hinting programs that must be run for correct
rendering; dropping them changes glyph advances and outlines. FreeType
refuses to load these fonts without hinting, so do the same in the
subsetter by ignoring HB_SUBSET_FLAGS_NO_HINTING for them.
Only TrueType-outline fonts qualify. Identify them by family name, and
by the length and checksum of their cvt, fpgm, and prep tables. The
lists and the name-to-ASCII semantics are ported from FreeType's
src/truetype/ttobjs.c; fontations has the same logic in
read-fonts/src/tables/glyf/hint_reliant.rs. Keep the detection in
hb-subset-hinting.hh rather than the subsetter, and add tests for both
paths.
Assisted-by: DeepSeek
* [subset] Refine hint-dependent font detection
- Store family names in a fixed-size table to avoid relocations.
- Read the name table directly instead of building the name
accelerator, and select the record with FreeType's platform and
language priority.
- Use hb_vector_t::set_storage() for the name buffer; treat an
allocation failure as a non-match.
- Pick the family name the way FreeType does: honor the OS/2 WWS bit,
and do not fall through to a lower-priority family name when the
preferred one exists but does not match.
- Add equality operators and use CheckSum::set_for_data() for table
checksums, rejecting unaligned data and handling the trailing bytes.
- Use face->table.glyf and drop the beyond-64K guard.
- Use ISALPHA/TOUPPER for the PDF randomization tag check.
- Add a regression test for the OS/2 WWS family selection.
Assisted-by: DeepSeek
* [perf] Add NO_HINTING subset benchmarks
Add a per-test NO_HINTING flag and enable it for the static TrueType
font benchmarks, so subsetting through the hint-dependent-font
detection path is measured. Benchmark names get a /nohinting suffix.
Assisted-by: DeepSeek
* [subset] Allow unaligned and unpadded checksum data
CalcTableChecksum() can add a trailing partial word. Use that so
_table_checksum() can pass arbitrary table data directly to
CheckSum::set_for_data() instead of rejecting unaligned data and
splitting off the padded prefix.
Add unit coverage for padded, unpadded, and unaligned data.
Assisted-by: DeepSeek
* [subset] Rename and cache the hint-dependent face check
Prefix the entry point with _hb_subset, and cache the answer in face
user data so repeated subsetting of the same face does not repeat the
name and table scans.
Assisted-by: DeepSeek
* [subset] Avoid allocating for the hint-dependent cache
Store the hint_dependent_cache_t value in the face user-data pointer
instead of allocating a bool. UNCACHED is zero, CACHED_FALSE is one,
and CACHED_TRUE is two.
Assisted-by: DeepSeek
* [test] Validate checksums against Python-generated vectors
Generate deterministic buffers and expected OpenType checksums with an
independent Python implementation, covering unaligned offsets and
lengths that are not multiples of four. The generator is committed as
src/generate-checksum-vectors.py and rewrites the marked block in the
unit test.
Assisted-by: DeepSeek
* [test] Drop the checksum vector generator
Keep the Python-generated vectors embedded in test-checksum.cc, but
remove the generator script and its markers. The comment records that
the values were generated independently with Python.
Assisted-by: DeepSeek
* [subset] Use CheckSum::CalcTableChecksum directly
Drop the trivial _table_checksum() wrapper and call
CheckSum::CalcTableChecksum() from the table-ID builder.
Assisted-by: DeepSeek
* [subset] Release the sanitized name table
hb_blob_ptr_t does not destroy its blob in its destructor, so add a
scope guard to release it on every return path.
Assisted-by: DeepSeek
* [subset] Limit cache enum scope
* [subset] Use dagger iteration for hint lists
Replace the family-name and font-ID membership loops with
hb_iter/hb_map/hb_any, and name the family-name capacity used by the
table and its iterator.
Assisted-by: DeepSeek
The subsetter cannot rewrite tables that refer to glyphs. That includes
legacy kern, AAT (ankr, bsln, just, kern, kerx, lcar, mort, morx, opbd,
prop), Graphite (Glat, Gloc, Silf), JSTF, SVG, LTSH, EBDT/EBLC, and
Apple's Zapf, bdat/bloc, gcid, and hvgl/hvpm tables. When one of these
is retained it is passed through unchanged, so renumbering glyphs makes
its glyph ids stale. Implicitly enable retain-gids in that case.
Make the plan use its own flags after this adjustment so every consumer
sees the effective retain-gids state, and add regression tests covering
AAT, Graphite, and the other unsubsettable glyph tables.
Assisted-by: DeepSeek
* [subset] Reuse sanitized tables cached on the face
Use the face table list and SFINAE to borrow sanitized tables from
the source face. Add borrow_sanitized_table() to suitable accelerators
and reuse the COLR accelerator during closure. Keep fallback tables
in the subset cache without taking references for each access.
Cache full GSUB/GPOS sanitization separately from shaping's lazy
sanitization. Inline their no-op blocklist hooks so the subset library
can instantiate the accelerators.
Add regressions for repeated subsets and GPOS data that passes lazy
sanitization but fails full validation.
Tested with meson test -C build: 299 passed, 1 skipped. Also ran
reduced-feature syntax checks and ASan/UBSan with failing malloc.
Assisted-by: Codex
* [ot-layout] Remove unused GSUB/GPOS blocklist hooks
Both hooks always return false. Remove the hooks and their dead
conditional from accelerator initialization.
Tested with meson test -C build: 299 passed, 1 skipped.
Assisted-by: Codex
* [subset] Borrow GDEF before shaping's blocklist
Keep ownership of the unfiltered sanitized GDEF table in the face
accelerator, alongside the potentially blocklisted shaping view.
Subsetting can borrow it without repeating sanitization or taking
references for each access.
Allow static borrowing accessors to initialize accelerators inside
libharfbuzz. GDEF uses this to keep its hidden blocklist implementation
out of the subset library's initialization path. Other accelerators
retain their instance accessors.
Add a synthetic blocklisted-font regression checking that shaping
still ignores GDEF while repeated subsets preserve its glyph classes
without rereading it.
Tested with meson test -C build: 299 passed, 1 skipped. Also ran GCC
and reduced-feature syntax checks, plus ASan/UBSan with failing malloc.
Assisted-by: Codex
The function documents len as the length of str, but located the ':'
separators with strpbrk() and matched "drop" with strcmp(), both of
which scan to the next NUL byte. A caller passing an exact-length,
non-NUL-terminated slice therefore got an out-of-bounds read, and bytes
beyond len could change or reject the parsed range.
Bound every scan by str+len: each strpbrk() becomes memchr() bounded by
end, the strcmp() becomes a len==4 && hb_memcmp() check, and the empty
-piece test !*str becomes str == end. This is the same discipline the
sibling parsers hb_feature_from_string()/hb_variation_from_string()
already follow. For len == -1 (the only in-tree caller) len becomes
strlen() first, so behaviour is unchanged. No public API/ABI change.
A regression test in test/api/test-subset.c passes prefixes of longer
literals with an explicit len and checks the NUL-terminated cases still
parse as before.
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-IL9ZX304.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Glyph zero is always reserved for .notdef. Reject mappings that assign
another retained glyph to it, so the output list has one entry per id.
Also bound the resulting glyph count by the widest supported count
field, MAXP's HBUINT24. Account for the unmapped glyphs and the initial
slot before assigning ids, avoiding wraparound and oversized counts in
table subsetters. The limit applies to the count, not the highest id.
Document these constraints and test valid renumbering, gaps, ignored
remapping of .notdef, reserved-id collisions, and out-of-range counts.
The regression and stock hb-subset both reproduce the issue under ASan
before the fix. All 293 tests pass after it, including the subset suite;
the API subset tests and command-line checks also pass ASan and UBSan.
Discovered by Anthropic's OSS Scanner, as vulnerability
ANT-2026-6I1RIFMQ.
Assisted-by: OpenAI Codex
Adding a fractional pinned delta to a large condition default in float
loses its low bits. A scaled 32-bit bias also loses bits when stored in
float tuples, and float variation-store accumulation can erase small
residuals when large deltas cancel.
Use double accumulation for layout condition evaluation and instancing,
keeping ordinary positioning and region-scalar arithmetic unchanged.
Split large biases into float-exact parts, which integer row assembly
combines before serializing a single neutral-region delta.
Add large-default fractional fixtures for GSUB and GPOS, with both
legacy and additive feature variations. Test a positive 1/12288 residual
at cancellation, partial and repeated instancing, and direct evaluation
of 32-bit variation deltas outside float's exact integer range.
Tests: full Meson suite (279 passed), sanitized item-varstore tests,
C++11 reduced-feature checks, and sanitized allocation sweeps over the
new fixtures (2334 full-font attempts and 21 row-encoder attempts).
Assisted-by: OpenAI Codex <codex@openai.com>
GSUB conditions need GDEF's remapped indices and precise condition
values, just as GPOS does. With avar2, GDEF waits for avar, allowing
GSUB to run first unless its dependency is explicit.
Add GSUB to the GDEF dependency and generate identity-avar2 fixtures
for legacy and additive feature variations in both layout tables.
The regressions compare shaping after partial and repeated instancing.
Tests: full Meson suite (279 passed).
Assisted-by: OpenAI Codex <codex@openai.com>
Partial instancing rounds the default and surviving deltas of format-2
layout conditions independently, moving their Boolean boundary and
changing GSUB or GPOS lookup selection.
Rescale variable conditions into private variation-store rows before
integer encoding, leaving shared positioning values unchanged. Prefer
exact integers; otherwise use the available signed 32-bit precision.
Carry defaults outside int16 in a neutral variation region.
Keep source values separate from output mappings so serialization retries
start with the original condition, and make private-row order independent
of source addresses. Propagate store-instancing failures to the serializer.
Add legacy and additive feature-variation fixtures covering nested
conditions, fractional coefficients, large defaults, shared positioning
rows, and a second instancing pass.
Tested: full Meson suite with and without experimental API (279 passed;
261 passed and 1 skipped respectively), C++11 reduced-feature syntax
checks, and C++11 sanitizer builds with failing allocation checks.
Assisted-by: OpenAI Codex <codex@openai.com>
Partial instancing used the rounded positioning delta to fold format-2
conditions. A positive fraction could round to zero and lose a lookup.
Evaluate the original GDEF store at the pinned/default coordinates when
the projected variation index becomes NO_VARIATION_INDEX instead.
Keep integer rounding for conditions with remaining variation and for
ordinary positioning values. The new helper is internal-only.
Extend the legacy condition grid and add an additive lookup regression
using existing fonts. The full Meson suite passes (281 tests, one skip),
including shape and subset suites. All 32 cross-library full/partial
GSUB/GPOS instancing diagnostics preserve the original shaping.
Assisted-by: OpenAI Codex <codex@openai.com>
A satisfied condition set becomes universal when all its conditions are
dropped, even if no remaining condition requested retention. Mark that
record universal and retain it while other axes remain, preventing
later records and an obsolete default catch-all from changing behavior.
Serialize reduced unconditional records with a null ConditionSet.
Regress GSUB and GPOS together, with an earlier conditional record and
LookupVariationRecord ADD_DEFAULT_LOOKUPS interaction. Regenerate the
existing instance goldens for the unconditional-record representation.
Testing: full Meson suite, 281 passed and one expected skip.
Assisted-by: OpenAI Codex <noreply@openai.com>
Legacy FeatureVariationRecords forced non-axis conditions to false when
choosing the new default features. Their empty range maps also compared
equal, discarding distinct conditional records during partial instancing.
Evaluate value and boolean conditions against the original GDEF store
at the new default, classify their surviving ranges conservatively, and
avoid range-only deduplication for complex conditions. Reuse the lookup
condition serializer to fold pinned axes and remap variation indices.
Materialize a false condition rather than emitting a null (true) offset.
Remove the unused condition-subset TODO stubs.
Add GSUB/GPOS coverage with 75 full/partial-instancing comparisons of
glyph selection and advances, covering formats 2-5 and null children.
Testing: meson test -C build (281 passed, 1 skipped); C++11 reduced-
feature syntax checks with HB_NO_VAR, HB_NO_BEYOND_64K, HB_NO_CUBIC_GLYF.
Assisted-by: OpenAI Codex <noreply@openai.com>
Extend the lookup-variation fixture with a GDEF ItemVariationStore-backed
ConditionValue and a GPOS conditional positioning lookup. This covers
variation-index evaluation, GPOS shaping, and lookup collection while
reusing the existing partial-instancing checks.
Tested with the full Meson suite and OTS validation of the fixture.
Assisted-by: OpenAI Codex <codex@openai.com>
Reduce LookupVariationRecord conditions to false, true, or a residual
condition when axes are pinned or restricted. Fold compound AND, OR,
and NOT conditions, remap value-condition variation indices, and emit a
constant condition when a surviving lookup becomes unconditional.
Extend the test font with a second axis and all condition formats so the
subset tests cover structural, full, and partial instancing behavior.
Tested with the full Meson test suite, targeted Clang HB_NO_VAR and GCC
builds, and OTS validation of the fixture.
Assisted-by: OpenAI Codex <codex@openai.com>
Resolve lookup variations at the pinned coordinates and store their final
lookup sets in the subset plan. Use those sets when serializing the main
Feature tables before dropping FeatureVariations from a full instance.
This reuses the shaping resolver so version 1.0 feature substitutions,
ADD_DEFAULT_LOOKUPS, compound conditions, and GDEF variation data are
evaluated consistently.
Tested with the full Meson test suite and a targeted HB_NO_VAR build.
Assisted-by: OpenAI Codex <codex@openai.com>
Subset FeatureVariations 1.1 lookup records while remapping feature and
lookup indices. Preserve all condition formats and remap variation
indices used by value conditions.
Keep features with lookup variations distinct during feature
deduplication, since equal default lookup lists do not imply equal
variable behavior.
Tested with the full Meson test suite and a targeted HB_NO_VAR build.
Assisted-by: OpenAI Codex <codex@openai.com>
Reconcile the beyond-64K table type changes with the dependency API,
graph result handling, and variation-budget updates from main. Preserve
the branch's wider table variants while adopting the new behavior.
Build and test with Meson (281 passed, 1 skipped).
Assisted-by: OpenAI Codex <noreply@openai.com>
SubsetGlyph stores borrowed slices into the source glyf table. Faces
created with a table callback may return a fresh blob on each request,
so destroying the population accelerator left those slices dangling
before they were serialized.
Retain the exact glyf blob through serialization. Exercise this path
by making the existing create-for-tables test return copied blobs.
Reported by WinD39 - Huynh Dinh Vu.
Fixes: https://issues.chromium.org/issues/536584255
Assisted-by: OpenAI Codex <codex@openai.com>
Resolve conflicts by taking hb_barrier() additions from main for all
switch dispatchers (COLR, Coverage, CursivePos, SinglePos,
ReverseChainSingleSubst) while keeping the beyond-64k extended
format cases.
For GDEF.hh: take main's clean GDEFVersion1_2<Types> template union
approach (which already handles beyond-64k via GDEFVersion1_2<MediumTypes>)
and incorporate the LigCaretList<Types> templating from beyond-64k,
expanding get_lig_carets() and collect_variation_indices() to dispatch
directly per version.
For coverage-graph.hh: keep beyond-64k's <Types> template but add
main's const qualifier to the vertex parameter.
For gsubgpos-graph.hh: keep beyond-64k's delegation to
OT::GSUBGPOS::get_lookup_list_field_offset() since GSUBGPOS uses the
flat struct approach in this branch.
For hb-ot-cmap-table.hh: keep beyond-64k's find_variation_selector_subtable()
which handles both format 14 and format 15 (beyond-64k).
Also fix PaintGlyph<Types>::paint_glyph out-of-line template definition
to include the template parameter, incorporating the get_solid_color
optimization from main.
Assisted-by: GitHub Copilot
Add the ability to create a subset plan which an be used to gather info on things like glyph mappings in the final subset. The plan can then be passed on to perform the subsetting operation.
Instead use inverted sets to handle requesting all features. Modifies feature collection in subset plan to intersect the set of requested features against the features in the font. This prevents iterating a fully filled feature tag set.
We might reintroduce it later, but for now remove, as it was unused.
Some things that should have been in this object (drop_hints, etc)
are already in hb_subset_input_t. So, for now, keep everything there.