9 Commits
Author SHA1 Message Date
Behdad EsfahbodandClaude Opus 4.8 8d01a1b148 [subset/cff2] Budget the region transforms built for partial instancing (#6635)
cff2_instancing_plan_t::create() builds k identity tuples of k cells
(then keeps a k-float column per surviving solver tuple) for every
entry of the CFF2 ItemVariationStore's VarData offset array, and
nothing bounded k (a 16-bit region count), the number of entries, or
their aliasing of one VarData.  The work is therefore quadratic in a
font field, so a 12 KB font cost 2.2 GB.

Charge those cells, before they are allocated, to a per-table budget
HB_BUDGET_SUBSET_CFF2_CELLS (2^24 cells) via the existing
hb_budget_spend helper, at both allocation sites (the k*k identity
tuples and the surviving solver columns).  Exhausting it fails create()
like any other planning failure, so the partial instance fails safely
(bounded at ~175 MB worst case) instead of exhausting memory.

Adds test_instance_cff2_vardata_budget: a 6.8 KB font with 40 offsets
aliasing one unused 800-region VarData must fail to partially instance
rather than build a region transform for each; it succeeds (keeping
CFF2 at hundreds of MB) before this change.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-I7KWU2X6.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-11 13:12:41 -06:00
Behdad Esfahbod f306676520 [subset] Tighten CFF2 absolute rounding (#6443)
Clear flex-depth deltas when they all round to zero and reject unexpected
operators in the absolute-rounding pass. Cover static fractional operands
in a charstring that also contains blends.

Remove command-capture branches made redundant by the full-instancing
control flow.

Testing: meson test -C build (295 passed, one skipped).

Assisted-by: OpenAI Codex
2026-10-27 15:42:35 -06:00
Behdad Esfahbod 75d8ac5d23 [subset] Reject unsupported symbolic CFF2 delta products (#6434)
Without coordinates, blend_arg_t stores only a flat delta vector.
A blend used as a later blend's delta loses its own deltas, changing
outlines during partial instancing or desubroutinization.

Reject that case in the usage and flatten passes. Retained subroutine
collection needs only blend identity, and full instancing evaluates
blends numerically, so keep both paths working. Mark CFF2 planning
failures as serialization errors so the subset API returns failure
instead of a face missing its outline table.

Add a generated two-axis font and exercise retained subsetting, full
instancing, rejected partial/desubroutinized products, and supported
nested defaults. The regression fails before the fix. Full Meson suite:
272 passed, one skipped.

Assisted-by: OpenAI Codex
2026-10-22 13:04:52 -06:00
Behdad Esfahbod de3011962e [subset] Round CFF2 instances on absolute coordinates (#6427)
Rounding relative charstring operands independently accumulates errors,
opening contours and displacing stem hints after instancing. Track
absolute outline coordinates and stem edges, round their defaults and
surviving variation deltas, then emit relative operands again.

Preserve compact path operators. Conservatively retain relative rounding
for every glyph containing flex1, avoiding variation-dependent direction
analysis. Leave charstrings without blends unchanged.

Add a generated regression font covering closed contours, compact curves,
flexes, masks, and fractional static operands. Check full and partial
instances, contour closure, point accuracy, and the flex1 fallback. Refresh
the existing serialized CFF expectations.

Testing: the complete Meson suite passes (294 passed, one skipped), as do
the CFF2 API tests under ASan and UBSan.

See-also: https://github.com/fonttools/fonttools/pull/4338
Assisted-by: OpenAI Codex
2026-10-22 07:01:35 -06:00
Behdad Esfahbod 3272df037c [subset] Allow CFF2 VariationStores larger than 65535 bytes (#6432)
OFF 2026 section 5.3.3.11.2 permits larger ItemVariationStores and
specifies a saturated length field of 65535. Partial CFF2 instancing
currently rejects these stores while serializing them.

Saturate the field while retaining the 32-bit offset size check.
Add a font with 200 referenced regions over 60 axes and exercise
partial instancing and extents at three locations. The test fails
before the fix because the output loses its CFF2 table.

Validation: full Meson suite, 272 passed and one skipped.

Assisted-by: OpenAI Codex
2026-10-21 19:59:08 -06:00
Behdad Esfahbod cb56bae961 [subset] Zero CFF2 instance bounds when no glyph contributes extents (#6430)
Instancing a CFF2 font with only empty outlines leaves the head bounds
accumulator at its inverted initialization sentinels. These are then
serialized as xMin=yMin=32767 and xMax=yMax=-32767.

Reset an empty accumulator to zero after collecting CFF2 extents. This
also provides a valid FontBBox if the instance is downgraded to CFF1.

Add a reproducible synthetic font and an API regression that fails before
the fix. The regression also checks preservation of the empty glyph's
advance and bearing. The complete Meson suite passes: 272 tests passed,
one skipped.

Assisted-by: Codex <noreply@openai.com>
2026-10-21 18:13:19 -06:00
nussaibah shaikh fe407340d5 Clamp transformed CFF2 blend deltas before int conversion (#6397)
When partially instancing a CFF2 font, the blend rewriters in
hb-subset-cff2.cc pass each old delta row through the region transform
and store the result with (int) round (transform_delta (...)).
transform_delta accumulates in double with no bound. Private DICT
operands can be BCD reals of any magnitude, so a StdVW blend delta of
1e12 yields about 3.7e11 at wght=300:600, and the double-to-int
conversion is undefined behavior (UBSan float-cast-overflow in
cff2_private_dict_blend_opset_t::rewrite_blends).

Saturate with hb_clamp_to<int>, as number_t::to_int already does.
The charstring blend rewriter uses the same expression and gets the
same clamp. Charstring operands are bounded by the 16.16 range, so
that site is not known to overflow in practice. Results that fit in
int are unchanged.

Add a regression test to test-instance-cff2 with a fixture generated
from AdobeVFPrototype.abc.otf. Under UBSAN_OPTIONS=halt_on_error=1 it
fails before the fix and passes after. The full Meson suite passes
under ASan+UBSan (290 ok).

Assisted-by: Claude
2026-10-15 11:16:49 -06: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 0f01a83622 [subset] add basic test for CFF2 subsetting.
FontTools does not yet support CFF2 subsetting so we can't add a comparison test. Instead add a golden file test.
2023-01-09 21:15:11 -07:00