From 75d8ac5d2313842550174eaab0cbaf653c8f2f77 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 22 Oct 2026 13:04:52 -0600 Subject: [PATCH] [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 --- src/hb-cff2-interp-cs.hh | 20 +++++++- src/hb-subset-cff2.cc | 6 +++ test/api/fonts/cff2-nested-delta.otf | Bin 0 -> 852 bytes test/api/generate-cff2-nested-delta-font.py | 33 +++++++++++++ test/api/test-instance-cff2.c | 52 ++++++++++++++++++++ 5 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 test/api/fonts/cff2-nested-delta.otf create mode 100644 test/api/generate-cff2-nested-delta-font.py diff --git a/src/hb-cff2-interp-cs.hh b/src/hb-cff2-interp-cs.hh index 2b705d49f..a04732c9a 100644 --- a/src/hb-cff2-interp-cs.hh +++ b/src/hb-cff2-interp-cs.hh @@ -204,6 +204,9 @@ struct cff2_cs_interp_env_t : cs_interp_env_t /* Subsetter instancing can defer rounding until absolute points are known. */ bool round_blends = true; + /* Some analysis passes need only blend presence, not symbolic deltas. */ + bool preserve_blends = true; + protected: const int *coords; unsigned int num_coords; @@ -222,6 +225,9 @@ struct cff2_cs_interp_env_t : cs_interp_env_t template , PARAM>> struct cff2_cs_opset_t : cs_opset_t, PARAM, PATH> { + /* Retained subroutine collection needs only blend identity. */ + static constexpr bool preserve_blends = false; + static void process_op (op_code_t op, cff2_cs_interp_env_t &env, PARAM& param) { switch (op) { @@ -269,8 +275,20 @@ struct cff2_cs_opset_t : cs_opset_t, PAR { double v = arg.to_real () + env.blend_deltas (blends); arg.set_real (env.round_blends ? round (v) : v); + return; } - else if (unlikely (arg.blending ())) + + /* Without coordinates, the flat delta vector cannot represent a + * product of region scalars. Do not discard a delta's own blend. */ + if (OPSET::preserve_blends && env.preserve_blends) + for (const ELEM &delta : blends) + if (unlikely (delta.blending ())) + { + env.set_error (); + return; + } + + if (unlikely (arg.blending ())) { /* A blend result used as an operand of a later blend: the value is * default + inner deltas + outer deltas, so accumulate the deltas. */ diff --git a/src/hb-subset-cff2.cc b/src/hb-subset-cff2.cc index 70b6b735c..3aa392b10 100644 --- a/src/hb-subset-cff2.cc +++ b/src/hb-subset-cff2.cc @@ -329,6 +329,8 @@ struct cff2_usage_param_t struct cff2_cs_opset_usage_t : cff2_cs_opset_t { + static constexpr bool preserve_blends = true; + static void flush_args_and_op (op_code_t op, cff2_cs_interp_env_t &env, cff2_usage_param_t& param) { param.has_flex1 |= op == OpCode_flex1; @@ -426,6 +428,8 @@ struct cff2_top_dict_op_serializer_t : cff_top_dict_op_serializer_t<> struct cff2_cs_opset_flatten_t : cff2_cs_opset_t { + static constexpr bool preserve_blends = true; + static void flush_args_and_op (op_code_t op, cff2_cs_interp_env_t &env, flatten_param_t& param) { bool skip_command = false; @@ -1224,6 +1228,7 @@ struct cff2_subset_plan used_fds.add (fd); cff2_cs_interp_env_t env (str, acc, fd); + env.preserve_blends = partial_instancing; cs_interpreter_t, cff2_cs_opset_usage_t, cff2_usage_param_t> interp (env); cff2_usage_param_t param; param.instancing = partial_instancing ? &instancing : nullptr; @@ -2024,6 +2029,7 @@ OT::cff2::accelerator_subset_t::subset (hb_subset_context_t *c) const if (unlikely (!cff2_plan.create (*this, c->plan))) { + /* A planning failure is not an intentionally empty outline table. */ c->serializer->err (HB_SERIALIZE_ERROR_OTHER); return false; } diff --git a/test/api/fonts/cff2-nested-delta.otf b/test/api/fonts/cff2-nested-delta.otf new file mode 100644 index 0000000000000000000000000000000000000000..9b41367a26148c8f42640e47bdff61bb8834f4fc GIT binary patch literal 852 zcmZ`%L2DCH5dPl2G+8BRsu6k+Sv3-GLJ$ceXj;s%k+!hC)rY&yh9(-4tqoEz_wB(; zFH$HTdJsJL6Z{AE=t+C<;K^PpJ+9yEt|0|Gk2mvu^XARGncddPN(&b;hK94yY}Qsc z_P+tv9)P#4<$JY8z3~Q6CGzJldZv#ecF9NN_t#&W!SAE*F`%!L*8|^puK938{E7QP zK!?5=KP3LiT?u;ONSzQt^{MQh8TFx`3Ad^8FHO&XfB2(9F89CoUkyXPi(+k4IZ)Kx zKPMV+SUBlFiICSx#WJ;IDzm0To8uBbA9J#3#Buy(@?IP38CIC(sl;(SD3B$X zDv!AgEB0|ivga<)a|^dKY~d1~rkL?XEN58pPgq;@hoSE!KZE1>-Ow!g?ai(kxPGS{ zgl@+R11!SF5Fxb(2McI&)rdTLy7U_?5w)>NW-x$D)*%mg<`Q|dLE3%N!2gxS=i8@t zv2r-OH?4LFjNzCk9GLC, 0); + hb_blob_destroy (cff2); + hb_font_t *font = hb_font_create (subset); + hb_variation_t variations[] = { + {HB_TAG ('w', 'g', 'h', 't'), 0.25f}, + {HB_TAG ('w', 'd', 't', 'h'), 1} + }; + hb_font_set_variations (font, variations, G_N_ELEMENTS (variations)); + hb_codepoint_t glyph; + hb_glyph_extents_t extents; + g_assert_true (hb_font_get_nominal_glyph (font, mode == 4 ? 65 : 66, &glyph)); + g_assert_true (hb_font_get_glyph_extents (font, glyph, &extents)); + g_assert_cmpint (extents.width, ==, mode == 4 ? 135 : 115); + hb_font_destroy (font); + hb_face_destroy (subset); + } + hb_face_destroy (face); +} + + int main (int argc, char **argv) { @@ -318,6 +369,7 @@ main (int argc, char **argv) hb_test_add (test_instance_cff2_empty_bounds); hb_test_add (test_instance_cff2_large_store); hb_test_add (test_instance_cff2_absolute_rounding); + hb_test_add (test_instance_cff2_nested_delta); return hb_test_run(); }