Commit Graph
18 Commits
Author SHA1 Message Date
Behdad EsfahbodandClaude Opus 4.8 fb58fbe259 [subset/cff2] Plan FDSelect from the real CFF2FDSelect type
cff2_subset_plan::create() cast acc.fdSelect (a CFF2FDSelect) to the
CFF1 FDSelect type for hb_plan_subset_cff_fdselect(), whose
get_fd_range() dispatch knows only formats 0 and 3.  A CFF2-only
format-4 FDSelect therefore reported FD 0 for every glyph, so the
planner kept only Font DICT 0: every retained glyph belonging to
another Font DICT lost that DICT's Private DICT and local subrs, and
when it called a local subr it either lost its outline or drew through
FD 0's subrs with the wrong shape.  The call still succeeded, writing a
single-Font-DICT font.  Format 4 is the only FDSelect format with a
16-bit FD index, so every CFF2 font with more than 256 Font DICTs is
affected.

The planner only needs get_fd_range() and format, so give CFF2FDSelect
its own get_fd_range() dispatching formats 0, 3 and 4, make
hb_plan_subset_cff_fdselect a template over the FDSelect type with
explicit instantiations for CFF1FDSelect and CFF2FDSelect (same pattern
as other explicitly instantiated subset helpers), and drop the cast.
The existing format-4 writer in hb_serialize_cff_fdselect is now
reachable.  Because a CFF2 font with >256 retained FDs can now
legitimately plan format 4, serialize_cff2_to_cff1() rejects that case
(CFF1 has no format 4) instead of emitting an invalid CFF table; with
fewer FDs the downgrade is unchanged.

Adds test_subset_cff2_fdselect_format4, which subsets the format-3 and
format-4 variants of a two-Font-DICT font and requires identical CFF2
output and glyph 2's extents; it fails before this change.

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-7RSDR0F0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-09 13:18:05 -06:00
ebraminio 2f489784c8 [subset] Support longintdict encoding (#6584)
* [test] Expand CFF number font parsing to subsetter encoding roundtrip

* [subset] Support longintdict encoding

It was a TODO for the encoder and this implements it.

* [test] Move roundtrip parse encode to its own function

* [cff] Extract nibble_buffer_t to avoid heap allocated hb_vector_t

* [cff] Use '(size + 1) / 2' buffer size instead of asserting evenness

Address review

* [cff] Minor touches

* [cff] Use idempotent ensure_error instead of set_error

As review
2026-11-07 16:29:39 -06:00
Behdad EsfahbodandNathan Keys a945625923 [subset] Bound CFF2 blends and serialization fields (#6546)
* [subset] Bound CFF2 blend values and serialization fields

Clamp fully pinned Private DICT blend sums before converting to int.
Reject CFF2 Top DICT sizes, variation-store counts, and region indexes
that cannot fit their serialized fields. Check VarRegionList counts
and byte-size multiplication before writing or allocating output.

Keep the CFF2 API regressions and move variation-region serialization
coverage into test-item-varstore. Use hb_always_assert and compact
boundary cases instead of custom macros, command-line selectors,
duplicate controls, and constant-condition checks. Verify that valid
region lists survive serialization and remapping unchanged.

The new CFF2 API regressions fail against unpatched main and pass with
these fixes. All 277 Meson tests pass, including all 133 subset tests.
The item-varstore tests also compile with HB_NO_VAR.

Based on the hardening patch in PR #6532.

Co-Authored-By: Nathan Keys <professor.moody@pm.me>
Assisted-by: OpenAI Codex

* [meson] Link the IUP optimizer into the CFF2 serialization test

The CFF2 serialization test instantiates tuple variations. Its object can
therefore reference iup_delta_optimize even though CFF2 does not enable
IUP optimization. Some compilers retain that reference and fail to link
the test; the local optimized build had eliminated it.

Include the IUP implementation in the test target, as the other tuple
and item varstore tests already do.

Reproduced the undefined reference by compiling the CFF2 test object at
-O0. It links and passes after adding the dependency. All 277 tests pass
with meson test -C build.

Assisted-by: OpenAI Codex

---------

Co-authored-by: Nathan Keys <professor.moody@pm.me>
2026-11-01 19:15:30 -07:00
Behdad Esfahbod dde7da182e [subset] Reject CFF calls without an immediate subroutine number
Retained subroutine remapping assumes the number preceding a call is
in the same program. Caller-supplied targets violate that assumption
and can silently change glyph outlines when unused subroutines are
removed. Enforce the existing support boundary in CFF1 and CFF2.

Report plan failures as serialization errors, rather than silently
dropping the CFF table. Explicit desubroutinization still handles the
regression fonts and preserves both outlines.

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

Assisted-by: OpenAI Codex
2026-10-22 17:06:10 +03:00
Behdad Esfahbod 4fc369ca36 [subset] Preserve long CFF DICT byte spans
Private DICT entries can accumulate several CFF2 blends before their
final operator. An eight-bit byte count truncated these spans modulo
256 during serialization, producing malformed output.

Use a full-width count and cover a 579-byte Private DICT with forty
variation regions and fourteen blended BlueValues.

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

Assisted-by: OpenAI Codex
2026-10-22 17:06:10 +03:00
Garret Rieger c6884377ec [subset] Add HB_SUBSET_FLAGS_IFTB_REQUIREMENTS flag.
When enabled the output subset conforms to the requirements for a base font to be patched by IFTB patches. IFTB is a proposed incremental font transfer patch. This new flag is set as experimental. Currently, setting this flag causes the output subset to also use long offsets for outline data in loca/glyf, gvar, CFF, and CFF2.

This change is a version of https://github.com/skef/harfbuzz/commit/3ae2fe2084d96f61d8ad1bbe42a6ef4e62ec830a rebased onto head w/ tests added.
2023-11-06 16:49:09 -07: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 942636ae13 [subset] Remove hb_subset_input_get/set_retain_gids. 2021-07-22 12:12:36 -07:00
Garret Rieger 77b4a1cd96 [subset] Remove hb_subset_input_get/set_desubroutinize. 2021-07-22 12:12:36 -07:00
Garret Rieger 8bf5d4d4f7 [subset] Remove hb_subset_input_get/set_drop_hints. 2021-07-22 12:12:36 -07:00
Michiharu Ariza f2908b4d8f Implement subset --regain-gids option with CFF1/2
along with api tests & expected results
2019-01-31 14:16:37 -08:00
Michiharu Ariza 0dfa584cb4 changed Adobe company name 2018-11-12 08:47:07 -08:00
Michiharu Ariza 0996c0ff62 implented no-desubroutinize with CFF2 along with API test
replaced AdobeVFPrototype.abc.otf with a hinted (maually) & subroutinized copy
replaced expected results as well
2018-11-07 14:48:37 -08:00
Michiharu Ariza ba055a8d53 fix build attempt ^3 2018-10-22 16:20:04 -07:00
Michiharu Ariza 3d3df5575c fix build attempt 2018-10-22 15:23:39 -07:00
Michiharu Ariza 1aeaee9dfc fixed cff2 subset test data 2018-10-03 17:44:45 -07:00
Michiharu Ariza 258b456566 Added CFF1 & CFF2 api tests 2018-09-24 16:50:47 -07:00