From e8f8ee612f30bb3724f1dd3522db09c270ec012d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Oct 2026 16:10:52 -0600 Subject: [PATCH] [subset] Ignore seac component lookups in CID-keyed CFF fonts (#6506) CID-keyed CFF charsets contain CIDs, not the standard SIDs needed by seac. Interpreting the invalid operator can therefore retain unrelated glyphs when their CIDs collide with the component SIDs from StandardEncoding. Reject CID-keyed fonts in get_seac_components so both subset closure and dependency collection skip these invalid lookups. Add a synthetic CID font with colliding CIDs and check that only .notdef and the requested glyph enter the subset plan. The regression fails before the fix with four retained glyphs instead of two. All 294 Meson tests pass, including the subset and API suites. Assisted-by: OpenAI Codex --- src/hb-ot-cff1-table.cc | 2 ++ test/api/fonts/cff1_cid_seac.otf | Bin 0 -> 696 bytes .../generate-cff-subset-regression-fonts.py | 23 +++++++++++++++++- test/api/test-subset-cff1.c | 23 ++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 test/api/fonts/cff1_cid_seac.otf diff --git a/src/hb-ot-cff1-table.cc b/src/hb-ot-cff1-table.cc index 437bdc091..4cbd79b78 100644 --- a/src/hb-ot-cff1-table.cc +++ b/src/hb-ot-cff1-table.cc @@ -665,6 +665,8 @@ _cff1_charstring_may_end_in_seac (const hb_ubytes_t &str, bool OT::cff1::accelerator_subset_t::get_seac_components (hb_codepoint_t glyph, hb_codepoint_t *base, hb_codepoint_t *accent) const { if (unlikely (!is_valid () || (glyph >= num_glyphs))) return false; + /* seac uses StandardEncoding names and is not defined in CID-keyed fonts. */ + if (is_CID ()) return false; unsigned int fd = fdSelect->get_fd (glyph); const hb_ubytes_t str = (*charStrings)[glyph]; diff --git a/test/api/fonts/cff1_cid_seac.otf b/test/api/fonts/cff1_cid_seac.otf new file mode 100644 index 0000000000000000000000000000000000000000..511eb2a5fbdd2d5ba356d61f80aeecb20ec3e254 GIT binary patch literal 696 zcmZ`%&r2IY6#iyswJKr#LG{v5x1v{n9mI+tF(Ke7Ma8z4*3}G2#AMTK0tyP=bMX)G z;@yIOg5tF&$wBbqu~)%jD9HAk*@YU=H_W{6``(*3Z)Y~QzMexbjvz6R&Su@~*60_& zS_I(d)~04t^O=u;AjRf(*{h-@f0EyjXNttpqzxW4I{?^fh ziSwi9USpbs6#>0Zy5W4xv@;*j$=QcZMT!S;j4p$pCAzkvgF?Zq0RoiZqk>hV zHLweh5o7u`^liS?m5sMCP2a`6xnI a((ZE{r`i1VxZ&tpUCl>1gy>(2n)wHHdS!k9 literal 0 HcmV?d00001 diff --git a/test/api/generate-cff-subset-regression-fonts.py b/test/api/generate-cff-subset-regression-fonts.py index 0ba145a6d..5844a6e3b 100644 --- a/test/api/generate-cff-subset-regression-fonts.py +++ b/test/api/generate-cff-subset-regression-fonts.py @@ -3,7 +3,7 @@ from pathlib import Path from fontTools.fontBuilder import FontBuilder from fontTools.misc.psCharStrings import T2CharString -from fontTools.cffLib import SubrsIndex, FDSelect +from fontTools.cffLib import SubrsIndex, FDSelect, FDArrayIndex, FontDict from fontTools.ttLib import TTFont OUT = Path(__file__).parent / "fonts" @@ -99,3 +99,24 @@ top = f["CFF "].cff.topDictIndex[0] top.Private.Subrs[0].setProgram([0, 0, 65, 194, "return"]) top.CharStrings["Aacute"].setProgram([-107, "callsubr", "endchar"]) f.save(OUT / "cff1_seac_subr_operands.otf") + +# A CID charset contains CIDs, not the standard SIDs needed by seac. Deliberately +# use CIDs 34 and 125, which collide with the SIDs for A and acute, so interpreting +# the invalid seac in CID 1000 would incorrectly retain those unrelated glyphs. +f = builder() +glyphs = [".notdef", "cid00034", "cid00125", "cid01000"] +f.setupGlyphOrder(glyphs) +f.setupCharacterMap({0x41: glyphs[1], 0x301: glyphs[2], 0xC1: glyphs[3]}) +f.setupHorizontalMetrics({g: (500, 0) for g in glyphs}) +cs = {g: T2CharString(program=["endchar"]) for g in glyphs} +cs["cid01000"].setProgram([0, 0, 65, 194, "endchar"]) +f.setupCFF("CIDSeacRegression", {"ROS": ("Adobe", "Identity", 0), "CIDCount": 1001}, cs, {}) +top = f.font["CFF "].cff.topDictIndex[0] +fd = FontDict() +fd.Private = top.Private +top.FDArray = FDArrayIndex() +top.FDArray.append(fd) +top.FDSelect = FDSelect(format=0) +top.FDSelect.gidArray = [0] * len(glyphs) +del top.Private +f.save(OUT / "cff1_cid_seac.otf") diff --git a/test/api/test-subset-cff1.c b/test/api/test-subset-cff1.c index 4a9629953..860e28daa 100644 --- a/test/api/test-subset-cff1.c +++ b/test/api/test-subset-cff1.c @@ -268,6 +268,28 @@ test_subset_cff1_seac (void) hb_face_destroy (face); } +static void +test_subset_cff1_cid_seac (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/cff1_cid_seac.otf"); + hb_subset_input_t *input = hb_subset_input_create_or_fail (); + hb_set_add (hb_subset_input_glyph_set (input), 3); + + hb_subset_plan_t *plan = hb_subset_plan_create_or_fail (face, input); + g_assert_nonnull (plan); + const hb_map_t *mapping = hb_subset_plan_old_to_new_glyph_mapping (plan); + /* The CID charset entries 34 and 125 are not seac components. */ + g_assert_cmpuint (hb_map_get_population (mapping), ==, 2); + g_assert_true (hb_map_has (mapping, 0)); + g_assert_true (hb_map_has (mapping, 3)); + g_assert_false (hb_map_has (mapping, 1)); + g_assert_false (hb_map_has (mapping, 2)); + + hb_subset_plan_destroy (plan); + hb_subset_input_destroy (input); + hb_face_destroy (face); +} + static void test_subset_cff1_seac_precheck (void) { @@ -586,6 +608,7 @@ main (int argc, char **argv) hb_test_add (test_subset_cff1_j_desubr_strip_hints); hb_test_add (test_subset_cff1_expert); hb_test_add (test_subset_cff1_seac); + hb_test_add (test_subset_cff1_cid_seac); hb_test_add (test_subset_cff1_seac_precheck); hb_test_add (test_subset_cff1_dotsection); hb_test_add (test_subset_cff1_retaingids);