From e0c3cbf16cd8d4f51e7e1b4ab5040b3ffe871cde Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 6 Aug 2024 06:46:44 -0600 Subject: [PATCH] [subset] Fail if source face has no glyphs Also return nullptr if any of the input pointers are nullptr. Before we were returning the empty face. Fixes https://github.com/harfbuzz/harfbuzz/issues/4824 --- src/hb-subset.cc | 10 ++++++++-- test/api/test-subset.c | 5 ++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/hb-subset.cc b/src/hb-subset.cc index f10ef54db..7cea9f183 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -594,14 +594,20 @@ static void _attach_accelerator_data (hb_subset_plan_t* plan, * @input: input to use for the subsetting. * * Subsets a font according to provided input. Returns nullptr - * if the subset operation fails. + * if the subset operation fails or the face has no glyphs. * * Since: 2.9.0 **/ hb_face_t * hb_subset_or_fail (hb_face_t *source, const hb_subset_input_t *input) { - if (unlikely (!input || !source)) return hb_face_get_empty (); + if (unlikely (!input || !source)) return nullptr; + + if (unlikely (!source->get_num_glyphs ())) + { + DEBUG_MSG (SUBSET, nullptr, "No glyphs in source font."); + return nullptr; + } hb_subset_plan_t *plan = hb_subset_plan_create_or_fail (source, input); if (unlikely (!plan)) { diff --git a/test/api/test-subset.c b/test/api/test-subset.c index 08c911076..6c859946a 100644 --- a/test/api/test-subset.c +++ b/test/api/test-subset.c @@ -43,8 +43,7 @@ test_subset_32_tables (void) hb_set_add (codepoints, 'c'); subset = hb_subset_or_fail (face, input); - g_assert (subset); - g_assert (subset != hb_face_get_empty ()); + g_assert (!subset); hb_subset_input_destroy (input); hb_face_destroy (subset); @@ -194,7 +193,7 @@ test_subset_plan (void) } static hb_blob_t* -_ref_table (hb_face_t *face, hb_tag_t tag, void *user_data) +_ref_table (hb_face_t *, hb_tag_t tag, void *user_data) { return hb_face_reference_table ((hb_face_t*) user_data, tag); }