Commit Graph
55 Commits
Author SHA1 Message Date
ebraminio f33d54ecf9 [subset] Preserve glyph ids for retained glyph-bearing tables (#6586)
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
2026-11-09 13:04:53 -06:00
Behdad Esfahbod 2823aad36c [subset] Reuse sanitized tables cached on the face (#6579)
* [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
2026-11-04 17:05:57 -06:00
Behdad EsfahbodandClaude Opus 4.8 9c093444ef [subset] Honour len in hb_subset_axis_range_from_string()
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>
2026-10-30 15:26:47 -06:00
Behdad Esfahbod 6156c7b4a7 [subset] Validate custom glyph mappings before assigning output ids (#6479)
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
2026-10-29 21:01:05 -06:00
Behdad Esfahbod 366065c366 [subset] Preserve large condition biases and delta residuals
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>
2026-10-05 18:11:53 -06:00
Behdad Esfahbod 726f2266e6 [subset] Wait for GDEF before instancing GSUB conditions
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>
2026-10-05 18:04:51 -06:00
Behdad Esfahbod 49d6ba3fa4 [subset] Preserve precision in variable layout conditions
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>
2026-10-02 14:14:29 -06:00
Behdad Esfahbod c034548995 [subset] Preserve the unrounded sign of constant layout conditions
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>
2026-10-02 11:09:38 -06:00
Behdad Esfahbod 955770eaa8 [subset] Preserve universal first-match records after axis pinning
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>
2026-10-02 06:20:51 -06:00
Behdad Esfahbod 81b68595b1 [subset] Instance FeatureVariationRecord condition formats 2-5
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>
2026-10-02 04:49:46 -06:00
Behdad Esfahbod f072bff4b0 [ot] Exercise GPOS lookup variations
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>
2026-10-01 20:40:06 -06:00
Behdad Esfahbod 3f39e24e75 [subset] Partially instantiate lookup conditions
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>
2026-10-01 19:43:47 -06:00
Behdad Esfahbod c8d6c273fb [subset] Instantiate LookupVariationRecord lookups
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>
2026-10-01 19:31:11 -06:00
Behdad Esfahbod 3d6677f05c [subset] Preserve LookupVariationRecord tables
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>
2026-10-01 19:25:17 -06:00
Behdad Esfahbod 17af97aae4 Merge remote-tracking branch 'origin/main' into beyond-64k
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>
2026-10-01 12:59:54 -06:00
Behdad Esfahbod d8dabe2594 [subset] Keep glyf table alive during serialization (#6150)
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>
2026-08-11 17:40:40 -06:00
copilot-swe-agent[bot] 96f6aa848a Merge branch 'main' into beyond-64k
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
2026-07-29 17:48:41 +00:00
Garret Rieger d7861576ae More fixes for review comments. 2026-07-14 16:26:49 -06:00
Garret Rieger 2725565dab Address review comments. 2026-07-14 16:26:49 -06:00
Garret Rieger 99380f0e44 Add new hb_subset_input_to_command_line_or_fail().
This generates an equivalent hb-subset command line string for a given subset input.

Assisted by gemini.
2026-07-14 16:26:49 -06:00
Behdad Esfahbod d930380490 [subset] Test callback-face extended table discovery
Verify uppercase MAXP is discovered and subset when a callback face
cannot enumerate its table tags.

Assisted-by: OpenAI Codex
2026-06-05 13:14:40 +02:00
Behdad Esfahbod 155e1e633b [test/api] Use g_assert_true instead of g_assert
The latter terminates the program. The former marks the test
as failing.
2025-04-06 03:49:15 -06:00
Garret Rieger a1e587b75a [subset] Add hb_subset_cff_get_charstrings_index and hb_subset_cff2_get_charstrings_index.
These methods allow retrieving the entire charstrings index structure from a CFF or CFF2 table.
2025-03-31 16:28:28 -06:00
Garret Rieger ae8b288db7 [subset] Correctly handle lifetime of charstrings data blob returned by hb_subset_cff_get_charstring_data. 2025-03-27 22:07:06 +00:00
Garret Rieger 0d4053b11d [subset] Add hb-subset.h API for retrieving the raw per glyph outline data from CFF and CFF2. 2025-03-27 20:20:52 +00:00
Behdad Esfahbod 191c6eedf3 Fix Linux bot 2024-08-06 06:59:32 -06:00
Behdad Esfahbod e0c3cbf16c [subset] Fail if source face has no glyphs
Also return nullptr if any of the input pointers are nullptr.
Before we were returning the empty face.

Fixes https://github.com/harfbuzz/harfbuzz/issues/4824
2024-08-06 06:50:54 -06:00
Garret Rieger 3472f73b79 [subset] also include no subset tables when guessing which tables are present. 2022-05-25 21:52:48 +00:00
Garret Rieger 9564d98739 [subset] fix subsetting of faces created via hb_face_create_for_tables.
Fixes #3609.
2022-05-25 21:16:37 +00:00
Garret Rieger f6071c16b0 [subset] Rename codepoint -> unicode in subset plan api 2022-02-28 23:45:40 +02:00
Garret Rieger 670ef070bd [subset] Change subset plan create to be or_fail. 2022-02-11 16:01:33 -08:00
Garret Rieger ae8d373bcf [subset] add subset plan reference, set/get user data functions. 2022-02-11 14:54:23 -08:00
Garret Rieger b65e48a786 [subset] Add subset plan to public API.
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.
2022-02-11 14:37:21 -08:00
Garret Rieger d700646c33 [subset] In preperation for 3.0.0 release remove legacy subsetting api methods. 2021-09-16 15:31:29 -06:00
Garret Rieger 102666dab7 [subset] add test for hb_subset_input_set (...). 2021-08-27 10:36:42 -07:00
Garret Rieger f2441a4b65 [subset] Remove retain all layout features flag.
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.
2021-08-24 18:17:07 -06:00
Garret Rieger cb05c363d7 [subset] add some basic tests for the legacy subset methods. 2021-08-14 10:37:02 -06:00
Garret Rieger f9d8e4a976 [subset] switch ..._set_flags to not take a mask. 2021-07-29 18:30:27 -07:00
Garret Rieger 3d534b146c [subset] convert subset input flags into bit flags.
Store the flags in a bit set. Updates the public api to work with the bit set directly.
2021-07-29 18:02:34 -07:00
Garret Rieger 9ab751ac9f [subset] Remove hb_subset(). Leaving just hb_subset_or_fail(). 2021-07-22 12:14:47 -07:00
Ebrahim Byagowi c110878cb6 [test] Unify font file opening across the tests 2018-10-21 11:27:05 +03:30
Behdad Esfahbod 3341c7fbfb [fuzzing] Move fuzzing fonts from api/ here 2018-10-17 15:04:35 -07:00
Chun-wei Fan 4035158de4 test/api/test-subset-*.c: Fix build on pre-C99
Ensure that we have the variables at the beginning of the block.  These
are the only fixes that we need for building HarfBuzz on older
compilers.
2018-10-09 09:43:36 -04:00
Behdad Esfahbod f39166f0c0 [subset] Remove unused hb_subset_profile_t
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.
2018-08-29 18:09:55 -07:00
Garret Rieger 1c3372786c [subset] fix infinite loop bug in looping through tables for subsetting. 2018-03-27 13:47:42 -06:00
Garret Rieger e597436b99 [subset] Disable glyf accelerator_t methods if it didn't successfully init. 2018-03-20 19:47:36 -06:00
Garret Rieger 7251181b56 [subset] Fix infinite loop in there are more then 32 tables. 2018-03-20 19:47:36 -06:00
Garret Rieger 1639bdd331 [subset] Remove test-subset, testing is planned to be done at the table level here with test/subset covering the complete subsetting operation. 2018-02-12 13:40:42 -08:00
Behdad Esfahbod 9682ef135f Minor fixups 2018-02-08 17:35:57 -06:00
Behdad Esfahbod c479a59988 [subset] Assemble font 2018-02-07 21:26:04 -06:00