[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
This commit is contained in:
Behdad Esfahbod authored and GitHub committed 2026-10-30 16:10:52 -06:00
1 parent 969dbf7931
commit e8f8ee612f
4 files changed
+47 -1

No files matched your search

+2
View File
@@ -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];
Binary file not shown.
@@ -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")
+23
View File
@@ -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);