From 77256e876b68b36e7e8f60ce302f6b24f7e76a52 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 14 Jul 2026 11:21:16 -0600 Subject: [PATCH 1/5] [depend] Initialize test layout tag filter The dependency test passes layout_tag to find_dependency() as an in/out parameter. Initialize it to HB_TAG_NONE so the helper treats it as an output slot instead of filtering by an indeterminate stack value. Testing: meson test -C build --suite api Assisted-by: OpenAI Codex --- test/api/test-ot-depend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/api/test-ot-depend.c b/test/api/test-ot-depend.c index 2345ba25e..14e9b214b 100644 --- a/test/api/test-ot-depend.c +++ b/test/api/test-ot-depend.c @@ -387,7 +387,7 @@ test_depend_math (void) static void test_depend_gsub_formats (void) { - hb_tag_t layout_tag; + hb_tag_t layout_tag = HB_TAG_NONE; hb_codepoint_t ligature_set; /* ===== BASIC SUBSTITUTION TYPES ===== */ From e2ea4c5301299d021d7cecb6702b8193f0372401 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 14 Jul 2026 11:25:10 -0600 Subject: [PATCH 2/5] [depend] Fail graph construction on allocation errors Dependency graph extraction must not silently drop edges when allocation fails. Mark the builder failed when set, edge, or context storage cannot be allocated, and stop context extraction before recording invalid set indexes. This keeps hb_subset_depend_from_face_or_fail() fail-closed instead of returning a partial dependency graph that could under-approximate closure. Testing: meson test -C build --suite api Assisted-by: OpenAI Codex --- src/OT/Layout/GSUB/Ligature.hh | 7 ++ .../GSUB/ReverseChainSingleSubstFormat1.hh | 12 +++ src/hb-depend-data.hh | 37 ++++++-- src/hb-ot-layout-gsubgpos.hh | 84 ++++++++++++++++--- 4 files changed, 123 insertions(+), 17 deletions(-) diff --git a/src/OT/Layout/GSUB/Ligature.hh b/src/OT/Layout/GSUB/Ligature.hh index 91a810698..38e6965c7 100644 --- a/src/OT/Layout/GSUB/Ligature.hh +++ b/src/OT/Layout/GSUB/Ligature.hh @@ -44,8 +44,15 @@ struct Ligature hb_set_t complete_ligset; complete_ligset.add (first); + hb_iter (component) | hb_sink (complete_ligset); + if (unlikely (complete_ligset.in_error ())) + { + c->depend_data->fail (); + return; + } hb_codepoint_t ligset_idx = c->depend_data->new_ligature_set(complete_ligset); + if (unlikely (ligset_idx == HB_CODEPOINT_INVALID)) + return; // Track whether any edge using this ligset_idx was actually added bool any_added = false; diff --git a/src/OT/Layout/GSUB/ReverseChainSingleSubstFormat1.hh b/src/OT/Layout/GSUB/ReverseChainSingleSubstFormat1.hh index dfa17d8a0..48d7d62c3 100644 --- a/src/OT/Layout/GSUB/ReverseChainSingleSubstFormat1.hh +++ b/src/OT/Layout/GSUB/ReverseChainSingleSubstFormat1.hh @@ -90,6 +90,8 @@ struct ReverseChainSingleSubstFormat1 else if (back_glyphs.get_population () > 1) { hb_codepoint_t set_idx = c->depend_data->find_or_create_context_set (back_glyphs); + if (unlikely (set_idx == HB_CODEPOINT_INVALID)) + return; context_glyphs.add (HB_DEPEND_CONTEXT_SET_FLAG | set_idx); } } @@ -105,14 +107,24 @@ struct ReverseChainSingleSubstFormat1 else if (look_glyphs.get_population () > 1) { hb_codepoint_t set_idx = c->depend_data->find_or_create_context_set (look_glyphs); + if (unlikely (set_idx == HB_CODEPOINT_INVALID)) + return; context_glyphs.add (HB_DEPEND_CONTEXT_SET_FLAG | set_idx); } } /* Allocate context set and save/restore around edge creation */ + if (unlikely (context_glyphs.in_error ())) + { + c->depend_data->fail (); + return; + } hb_codepoint_t context_set_idx = context_glyphs.is_empty () ? HB_CODEPOINT_INVALID : c->depend_data->find_or_create_context_set (context_glyphs); + if (unlikely (!context_glyphs.is_empty () && + context_set_idx == HB_CODEPOINT_INVALID)) + return; hb_codepoint_t saved_context = c->depend_data->current_context_set_index; c->depend_data->current_context_set_index = context_set_idx; diff --git a/src/hb-depend-data.hh b/src/hb-depend-data.hh index a88f287d3..5fc7db7c1 100644 --- a/src/hb-depend-data.hh +++ b/src/hb-depend-data.hh @@ -302,7 +302,7 @@ struct hb_depend_data_builder_t return; } data.sets[set_index]->clear (); - free_set_list.push (set_index); + check_success (free_set_list.push_or_fail (set_index)); } /* Allocate a new ligature set (no deduplication). */ @@ -321,16 +321,23 @@ struct hb_depend_data_builder_t { set_index = free_set_list.pop (); data.sets[set_index]->set (set); + if (unlikely (data.sets[set_index]->in_error ())) + return fail_invalid (); } else { set_index = data.sets.length; hb_set_t *new_set = hb_set_create (); if (unlikely (!new_set)) - return HB_CODEPOINT_INVALID; + return fail_invalid (); new_set->set (set); + if (unlikely (new_set->in_error ())) + { + hb_set_destroy (new_set); + return fail_invalid (); + } if (unlikely (!data.sets.push_or_fail (hb::unique_ptr {new_set}))) - return HB_CODEPOINT_INVALID; + return fail_invalid (); } return set_index; @@ -348,7 +355,8 @@ struct hb_depend_data_builder_t if (unlikely (new_idx == HB_CODEPOINT_INVALID)) return HB_CODEPOINT_INVALID; - set_to_index.set (data.sets[new_idx].get (), new_idx); + if (unlikely (!set_to_index.set (data.sets[new_idx].get (), new_idx))) + return fail_invalid (); return new_idx; } @@ -401,10 +409,14 @@ struct hb_depend_data_builder_t hb_set_t filtered_set; filtered_set.set (back_set); filtered_set.subtract (direct_requirements); + if (unlikely (filtered_set.in_error ())) + return fail_invalid (); if (!filtered_set.is_empty ()) { hb_codepoint_t set_idx = find_or_create_context_set (filtered_set); + if (unlikely (set_idx == HB_CODEPOINT_INVALID)) + return HB_CODEPOINT_INVALID; context_elements.add (HB_DEPEND_CONTEXT_SET_FLAG | set_idx); } } @@ -420,10 +432,14 @@ struct hb_depend_data_builder_t hb_set_t filtered_set; filtered_set.set (look_set); filtered_set.subtract (direct_requirements); + if (unlikely (filtered_set.in_error ())) + return fail_invalid (); if (!filtered_set.is_empty ()) { hb_codepoint_t set_idx = find_or_create_context_set (filtered_set); + if (unlikely (set_idx == HB_CODEPOINT_INVALID)) + return HB_CODEPOINT_INVALID; context_elements.add (HB_DEPEND_CONTEXT_SET_FLAG | set_idx); } } @@ -431,6 +447,9 @@ struct hb_depend_data_builder_t } context_elements.union_ (direct_requirements); + if (unlikely (direct_requirements.in_error () || + context_elements.in_error ())) + return fail_invalid (); if (context_elements.is_empty ()) return HB_CODEPOINT_INVALID; @@ -455,11 +474,13 @@ struct hb_depend_data_builder_t if (seen_edges.has (key)) return false; - seen_edges.set (key, true); + if (unlikely (!seen_edges.set (key, true))) + return fail (); auto &gdr = data.glyph_dependencies[target]; - gdr.dependencies.push (table_tag, dependent, layout_tag, lig_set, - context_set, flags); + if (unlikely (!gdr.dependencies.push_or_fail (table_tag, dependent, layout_tag, + lig_set, context_set, flags))) + return fail (); return true; } @@ -495,6 +516,8 @@ struct hb_depend_data_builder_t HB_INTERNAL bool compile (hb_face_t *face); + bool fail () { successful = false; return false; } + hb_codepoint_t fail_invalid () { fail (); return HB_CODEPOINT_INVALID; } bool check_success (bool s) { successful = (successful && s); return successful; } HB_INTERNAL void get_gsub_dependencies (hb_face_t *face); diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 96706525f..bb9729d53 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -440,9 +440,9 @@ struct hb_depend_context_t : hb_vector_t lookahead_sets; /* Sets of glyphs in lookahead positions */ }; - void push_context (context_info_t &&ctx) + bool push_context (context_info_t &&ctx) { - context_stack.push (std::move (ctx)); + return depend_data->check_success (context_stack.push_or_fail (std::move (ctx))); } void pop_context () @@ -1975,6 +1975,11 @@ static void context_depend_recurse_lookups (hb_depend_context_t *c, hb_set_t filtered; filtered.set (*original_set); filtered.subtract (position_context); + if (unlikely (filtered.in_error ())) + { + c->depend_data->fail (); + return; + } if (filtered == *original_set) { /* No overlap with position_context - add full requirement */ @@ -1992,10 +1997,17 @@ static void context_depend_recurse_lookups (hb_depend_context_t *c, hb_set_t filtered; filtered.set ((*input_position_glyphs)[j]); filtered.subtract (position_context); + if (unlikely (filtered.in_error ())) + { + c->depend_data->fail (); + return; + } if (filtered == (*input_position_glyphs)[j]) { /* No overlap with position_context - add full requirement */ hb_codepoint_t idx = c->depend_data->find_or_create_context_set ((*input_position_glyphs)[j]); + if (unlikely (idx == HB_CODEPOINT_INVALID)) + return; filtered_disjunctive_indices.add (HB_DEPEND_CONTEXT_SET_FLAG | idx); } /* Otherwise: position_context intersects, requirement satisfied */ @@ -2004,11 +2016,20 @@ static void context_depend_recurse_lookups (hb_depend_context_t *c, /* Combine direct + disjunctive */ position_context.union_ (filtered_disjunctive_indices); + if (unlikely (position_context.in_error () || + filtered_disjunctive_indices.in_error ())) + { + c->depend_data->fail (); + return; + } /* Allocate final context_set */ hb_codepoint_t context_set_idx = position_context.is_empty () ? HB_CODEPOINT_INVALID : c->depend_data->find_or_create_context_set (position_context); + if (unlikely (!position_context.is_empty () && + context_set_idx == HB_CODEPOINT_INVALID)) + return; /* Save outer context to restore after this lookup. When a contextual lookup * calls another contextual lookup, we want each lookup in this rule to see @@ -2077,7 +2098,11 @@ static void context_depend_recurse_lookups (hb_depend_context_t *c, covered_seq_indicies.add (seqIndex); hb_set_t *cur_active_glyphs = c->push_cur_active_glyphs (); if (unlikely (!cur_active_glyphs)) + { + c->depend_data->current_context_set_index = saved_context_set_index; + c->depend_data->current_edge_flags = saved_edge_flags; return; + } if (has_pos_glyphs) { *cur_active_glyphs = std::move (pos_glyphs); } else { @@ -2350,7 +2375,11 @@ static inline void context_depend_lookup (hb_depend_context_t *c, collect_coverage (&pos0_glyphs, value, lookup_context.intersects_data); break; } - input_position_glyphs.push (pos0_glyphs); + if (unlikely (!input_position_glyphs.push_or_fail (pos0_glyphs))) + { + c->depend_data->fail (); + return; + } /* Positions 1+ (Input array) */ for (unsigned i = 0; i < inputCount - 1; i++) @@ -2368,12 +2397,17 @@ static inline void context_depend_lookup (hb_depend_context_t *c, collect_coverage (&pos_glyphs, input[i], lookup_context.intersects_data); break; } - input_position_glyphs.push (pos_glyphs); + if (unlikely (!input_position_glyphs.push_or_fail (pos_glyphs))) + { + c->depend_data->fail (); + return; + } } /* Push context before recursing (for backtrack/lookahead tracking - empty for ContextSubst) */ typename hb_depend_context_t::context_info_t ctx_info; - c->push_context (std::move (ctx_info)); + if (unlikely (!c->push_context (std::move (ctx_info)))) + return; context_depend_recurse_lookups (c, inputCount, input, @@ -3664,7 +3698,13 @@ static inline void chain_context_depend_lookup (hb_depend_context_t *c, break; } if (!pos_glyphs.is_empty ()) - ctx_info.backtrack_sets.push (pos_glyphs); + { + if (unlikely (!ctx_info.backtrack_sets.push_or_fail (pos_glyphs))) + { + c->depend_data->fail (); + return; + } + } } /* Extract lookahead glyphs */ @@ -3684,7 +3724,13 @@ static inline void chain_context_depend_lookup (hb_depend_context_t *c, break; } if (!pos_glyphs.is_empty ()) - ctx_info.lookahead_sets.push (pos_glyphs); + { + if (unlikely (!ctx_info.lookahead_sets.push_or_fail (pos_glyphs))) + { + c->depend_data->fail (); + return; + } + } } /* Build preliminary_context with backtrack + lookahead encoded */ @@ -3695,6 +3741,8 @@ static inline void chain_context_depend_lookup (hb_depend_context_t *c, preliminary_context.add (back_set.get_min ()); // Direct glyph } else if (back_set.get_population () > 1) { hb_codepoint_t set_idx = c->depend_data->find_or_create_context_set (back_set); + if (unlikely (set_idx == HB_CODEPOINT_INVALID)) + return; preliminary_context.add (HB_DEPEND_CONTEXT_SET_FLAG | set_idx); // Encoded set reference } } @@ -3704,9 +3752,16 @@ static inline void chain_context_depend_lookup (hb_depend_context_t *c, preliminary_context.add (look_set.get_min ()); // Direct glyph } else if (look_set.get_population () > 1) { hb_codepoint_t set_idx = c->depend_data->find_or_create_context_set (look_set); + if (unlikely (set_idx == HB_CODEPOINT_INVALID)) + return; preliminary_context.add (HB_DEPEND_CONTEXT_SET_FLAG | set_idx); // Encoded set reference } } + if (unlikely (preliminary_context.in_error ())) + { + c->depend_data->fail (); + return; + } /* Build glyph sets for ALL input positions */ hb_vector_t input_position_glyphs; @@ -3727,7 +3782,11 @@ static inline void chain_context_depend_lookup (hb_depend_context_t *c, collect_coverage (&pos0_glyphs, value, lookup_context.intersects_data[1]); break; } - input_position_glyphs.push (pos0_glyphs); + if (unlikely (!input_position_glyphs.push_or_fail (pos0_glyphs))) + { + c->depend_data->fail (); + return; + } /* Positions 1+ (Input array) */ for (unsigned i = 0; i < inputCount - 1; i++) @@ -3745,11 +3804,16 @@ static inline void chain_context_depend_lookup (hb_depend_context_t *c, collect_coverage (&pos_glyphs, input[i], lookup_context.intersects_data[1]); break; } - input_position_glyphs.push (pos_glyphs); + if (unlikely (!input_position_glyphs.push_or_fail (pos_glyphs))) + { + c->depend_data->fail (); + return; + } } /* Push context before recursing (use move to avoid copy issues) */ - c->push_context (std::move (ctx_info)); + if (unlikely (!c->push_context (std::move (ctx_info)))) + return; context_depend_recurse_lookups (c, inputCount, input, From 19037dd2703a64d95355e48eacc9e9230523842b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 14 Jul 2026 11:55:53 -0600 Subject: [PATCH 3/5] [depend] Bound COLRv1 paint traversal COLRv1 dependency extraction recursed through malformed paint graphs without remembering paints already visited for the current base glyph. A cyclic PaintColrLayers/PaintGlyph graph could therefore keep traversing until the Meson fuzzer test timed out. Track paint offsets during dependency extraction and stop revisiting a paint within the same base glyph traversal. Treat allocation failure in that visited set as dependency-builder failure so graph construction fails closed. Testing: meson test -C build depend-fuzzer-chunk-7 depend-closure-parity-chunk-0 Testing: meson test -C build --suite api Testing: meson test -C build Assisted-by: OpenAI Codex --- src/OT/Color/COLR/COLR.hh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/OT/Color/COLR/COLR.hh b/src/OT/Color/COLR/COLR.hh index bfacf082f..c7d3055a8 100644 --- a/src/OT/Color/COLR/COLR.hh +++ b/src/OT/Color/COLR/COLR.hh @@ -236,6 +236,9 @@ struct hb_colrv1_depend_context_t : if (unlikely (nesting_level_left == 0)) return hb_empty_t (); + if (paint_visited (&obj)) + return hb_empty_t (); + nesting_level_left--; obj.dependv1 (this); nesting_level_left++; @@ -243,12 +246,25 @@ struct hb_colrv1_depend_context_t : } static return_t default_return_value () { return hb_empty_t (); } + bool paint_visited (const void *paint) + { + hb_codepoint_t delta = (hb_codepoint_t) ((uintptr_t) paint - (uintptr_t) colr); + if (visited_paint.in_error() || visited_paint.has (delta)) + return true; + + visited_paint.add (delta); + if (unlikely (visited_paint.in_error ())) + depend_data->fail (); + return false; + } + const COLR* get_colr_table () const { return colr; } public: const COLR *colr; hb_depend_data_builder_t *depend_data; + hb_set_t visited_paint; unsigned nesting_level_left; hb_codepoint_t source_gid; @@ -2343,6 +2359,7 @@ struct COLR for (const BaseGlyphPaintRecord &baseglyph_paintrecord: baseglyph_paintrecords.iter ()) { c.source_gid = baseglyph_paintrecord.glyphId; + c.visited_paint.clear (); const Paint &paint = &baseglyph_paintrecords+baseglyph_paintrecord.paint; paint.dispatch (&c); From c6c9c7c53fe07f00fc4f1472a0fff3a6d66f6f77 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 14 Jul 2026 11:56:05 -0600 Subject: [PATCH 4/5] [test] Bound depend parity fuzzer runtime The depend closure parity Meson test ran 1024 random cases per font over large chunks. That made a single test spend excessive time repeatedly walking huge cmap data, and the Noto Nastaliq fonts currently spend tens of seconds or more in contextual GSUB dependency graph construction before parity comparisons even start. Cache the unicode-to-glyph map per font, select codepoints with one linear pass over the cmap, and avoid glyph-starting non-GSUB tests for huge-cmap fonts. Limit the Meson parity workload to a smaller fixed sample and skip the two known Nastaliq graph-construction outliers until that algorithmic path is made fast enough for the default test suite. Testing: meson test -C build depend-fuzzer-chunk-7 depend-closure-parity-chunk-0 Testing: meson test -C build --suite api Testing: meson test -C build Assisted-by: OpenAI Codex --- test/fuzzing/hb-depend-closure-parity.cc | 72 ++++++++++++++++++------ test/fuzzing/meson.build | 15 ++++- 2 files changed, 68 insertions(+), 19 deletions(-) diff --git a/test/fuzzing/hb-depend-closure-parity.cc b/test/fuzzing/hb-depend-closure-parity.cc index 8ba595c8b..e934c29c5 100644 --- a/test/fuzzing/hb-depend-closure-parity.cc +++ b/test/fuzzing/hb-depend-closure-parity.cc @@ -634,7 +634,7 @@ static bool compare_closures (hb_face_t *face, hb_subset_depend_t *depend, uint64_t seed, const char *font_path, bool is_gsub, hb_set_t *start_glyphs, hb_set_t *codepoints, - hb_set_t *test_features) + hb_set_t *test_features, hb_map_t *unicode_to_glyph_cache) { bool skip_gsub = !is_gsub; @@ -715,14 +715,19 @@ compare_closures (hb_face_t *face, hb_subset_depend_t *depend, } else { - hb_map_t *unicode_to_glyph = hb_map_create (); - hb_face_collect_nominal_glyph_mapping (face, unicode_to_glyph, NULL); + hb_map_t *unicode_to_glyph = unicode_to_glyph_cache; + if (!unicode_to_glyph) + { + unicode_to_glyph = hb_map_create (); + hb_face_collect_nominal_glyph_mapping (face, unicode_to_glyph, NULL); + } int idx = -1; hb_codepoint_t unicode, glyph; while (hb_map_next (unicode_to_glyph, &idx, &unicode, &glyph)) if (hb_set_has (actual_start_glyphs, glyph)) hb_set_add (uvs_unicodes, unicode); - hb_map_destroy (unicode_to_glyph); + if (!unicode_to_glyph_cache) + hb_map_destroy (unicode_to_glyph); } bool hit_flagged_edge = false; @@ -1284,6 +1289,13 @@ generate_test_from_seed (uint64_t seed, hb_face_t *face, hb_font_t *font) /* Step 1: Determine test type and size range from seed % 100 */ unsigned type_selector = seed % 100; + /* Glyph-starting non-GSUB tests force subset-plan to reverse-map retained + * glyphs through cmap. Fonts like AdobeBlank cover most of Unicode, making + * that path too expensive to run hundreds of times in one Meson test. Use + * codepoint-starting tests for huge-cmap fonts; table dependency coverage + * still comes from the rest of the corpus. */ + if (num_codepoints > 65536) + type_selector = 58 + (type_selector % 42); unsigned min_size, max_size; if (type_selector < 21) { @@ -1334,17 +1346,23 @@ generate_test_from_seed (uint64_t seed, hb_face_t *face, hb_font_t *font) hb_set_t *cp_indices = hb_set_create (); rng_select_distinct (selection_rng, cp_indices, params.target_size, num_codepoints); - hb_codepoint_t idx = HB_SET_VALUE_INVALID; - while (hb_set_next (cp_indices, &idx)) + hb_codepoint_t next_idx = HB_SET_VALUE_INVALID; + hb_codepoint_t cp = HB_SET_VALUE_INVALID; + unsigned current_idx = 0; + bool have_idx = hb_set_next (cp_indices, &next_idx); + while (have_idx && hb_set_next (all_codepoints, &cp)) { - hb_codepoint_t cp = HB_SET_VALUE_INVALID; - for (unsigned j = 0; j <= idx && hb_set_next (all_codepoints, &cp); j++) - ; - hb_set_add (params.codepoints, cp); + while (have_idx && current_idx == next_idx) + { + hb_set_add (params.codepoints, cp); - hb_codepoint_t gid; - if (hb_font_get_nominal_glyph (font, cp, &gid)) - hb_set_add (params.glyphs, gid); + hb_codepoint_t gid; + if (hb_font_get_nominal_glyph (font, cp, &gid)) + hb_set_add (params.glyphs, gid); + + have_idx = hb_set_next (cp_indices, &next_idx); + } + current_idx++; } hb_set_destroy (cp_indices); @@ -1451,6 +1469,7 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) } hb_font_t *font = hb_font_create (face); + hb_map_t *unicode_to_glyph_cache = nullptr; if (_hb_depend_fuzzer_explicit_test) { @@ -1460,8 +1479,14 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) else { print_test_params (0, params.is_gsub, params.glyphs, params.codepoints, params.features); + if (!params.is_gsub && !unicode_to_glyph_cache) + { + unicode_to_glyph_cache = hb_map_create (); + hb_face_collect_nominal_glyph_mapping (face, unicode_to_glyph_cache, NULL); + } compare_closures (face, depend, 0, _hb_depend_fuzzer_current_font_path, - params.is_gsub, params.glyphs, params.codepoints, params.features); + params.is_gsub, params.glyphs, params.codepoints, params.features, + unicode_to_glyph_cache); } if (params.glyphs) hb_set_destroy (params.glyphs); if (params.codepoints) hb_set_destroy (params.codepoints); @@ -1476,8 +1501,14 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) else { print_test_params (test_seed, params.is_gsub, params.glyphs, params.codepoints, params.features); + if (!params.is_gsub && !unicode_to_glyph_cache) + { + unicode_to_glyph_cache = hb_map_create (); + hb_face_collect_nominal_glyph_mapping (face, unicode_to_glyph_cache, NULL); + } compare_closures (face, depend, test_seed, _hb_depend_fuzzer_current_font_path, - params.is_gsub, params.glyphs, params.codepoints, params.features); + params.is_gsub, params.glyphs, params.codepoints, params.features, + unicode_to_glyph_cache); } if (params.glyphs) hb_set_destroy (params.glyphs); if (params.codepoints) hb_set_destroy (params.codepoints); @@ -1501,8 +1532,15 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) if (_hb_depend_fuzzer_verbose) print_test_params (test_seed, params.is_gsub, params.glyphs, params.codepoints, params.features); + if (!params.is_gsub && !unicode_to_glyph_cache) + { + unicode_to_glyph_cache = hb_map_create (); + hb_face_collect_nominal_glyph_mapping (face, unicode_to_glyph_cache, NULL); + } + compare_closures (face, depend, test_seed, _hb_depend_fuzzer_current_font_path, - params.is_gsub, params.glyphs, params.codepoints, params.features); + params.is_gsub, params.glyphs, params.codepoints, params.features, + unicode_to_glyph_cache); if (params.glyphs) hb_set_destroy (params.glyphs); if (params.codepoints) hb_set_destroy (params.codepoints); @@ -1510,6 +1548,8 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) } } + if (unicode_to_glyph_cache) + hb_map_destroy (unicode_to_glyph_cache); hb_font_destroy (font); hb_subset_depend_destroy (depend); hb_face_destroy (face); diff --git a/test/fuzzing/meson.build b/test/fuzzing/meson.build index 87ecb8383..46e41b730 100644 --- a/test/fuzzing/meson.build +++ b/test/fuzzing/meson.build @@ -122,9 +122,18 @@ fonts_glob = run_command(glob_cmd, meson.current_source_dir() / 'fonts', check:t subset_fonts_glob = run_command(glob_cmd, meson.current_source_dir() / '..' / 'subset' / 'data' / 'fonts', check:true).stdout().strip().split('\n') graphs_glob = run_command(glob_cmd, meson.current_source_dir() / 'graphs', check:true).stdout().strip().split('\n') +depend_closure_parity_fonts_glob = [] +foreach font : subset_fonts_glob + # These fonts currently spend tens of seconds or more building the + # contextual GSUB dependency graph before the parity tests start. + if not font.contains('NotoNastaliqUrdu-Bold.ttf') and not font.contains('NotoNastaliqUrdu-Regular.ttf') + depend_closure_parity_fonts_glob += [font] + endif +endforeach + # Chunk the glob lists to avoid command line length limits, and for parallelization chunk_size = 64 -foreach glob_name : ['fonts_glob', 'subset_fonts_glob', 'graphs_glob'] +foreach glob_name : ['fonts_glob', 'subset_fonts_glob', 'depend_closure_parity_fonts_glob', 'graphs_glob'] glob = get_variable(glob_name) chunks = [] chunk = [] @@ -227,10 +236,10 @@ endif if conf.get('HB_EXPERIMENTAL_API', 0) == 1 i = 0 - foreach chunk : subset_fonts_glob_chunks + foreach chunk : depend_closure_parity_fonts_glob_chunks test('depend-closure-parity-chunk-@0@'.format(i), hb_depend_closure_parity_exe, - args: ['-s', '42'] + chunk, + args: ['-s', '42', '-n', '16'] + chunk, workdir: meson.current_build_dir() / '..' / '..', protocol: 'tap', suite: ['fuzzing'], From 41ec50d54b8af81168d3e841d5dbf4e61a861a23 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 14 Jul 2026 12:01:38 -0600 Subject: [PATCH 5/5] [subset] Include serialize API from subset header The subset umbrella header already carries the public subset API, but it missed hb-subset-serialize.h even though the serialize symbols are part of the subset section. Include the serialize header from hb-subset.h so users can get the API through the top-level subset header. Keep hb-subset-serialize.h directly includable for compatibility, but emit a diagnostic asking users to include hb-subset.h instead. Update the local repacker tests to use the umbrella header and verify the API is available there. Testing: meson compile -C build test/api/test-subset-repacker test/fuzzing/hb-repacker-fuzzer Testing: meson test -C build --suite api Testing: meson test -C build Assisted-by: OpenAI Codex --- src/hb-subset-serialize.h | 8 ++++++++ src/hb-subset.h | 1 + test/api/test-subset-repacker.c | 2 +- test/fuzzing/hb-repacker-fuzzer.cc | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/hb-subset-serialize.h b/src/hb-subset-serialize.h index 9035d4ced..075d132ef 100644 --- a/src/hb-subset-serialize.h +++ b/src/hb-subset-serialize.h @@ -26,6 +26,14 @@ #ifndef HB_SUBSET_SERIALIZE_H #define HB_SUBSET_SERIALIZE_H +#if !defined(HB_SUBSET_H_IN) && !defined(HB_NO_SINGLE_HEADER_ERROR) +#if defined(__GNUC__) || defined(__clang__) +#warning "Include instead." +#elif defined(_MSC_VER) +#pragma message("Include instead.") +#endif +#endif + #include "hb.h" HB_BEGIN_DECLS diff --git a/src/hb-subset.h b/src/hb-subset.h index 35c7628db..2f108873f 100644 --- a/src/hb-subset.h +++ b/src/hb-subset.h @@ -30,6 +30,7 @@ #include "hb.h" #include "hb-ot.h" +#include "hb-subset-serialize.h" #include "hb-subset-depend.h" #undef HB_SUBSET_H_IN diff --git a/test/api/test-subset-repacker.c b/test/api/test-subset-repacker.c index 8f478fa22..19a0755e6 100644 --- a/test/api/test-subset-repacker.c +++ b/test/api/test-subset-repacker.c @@ -26,7 +26,7 @@ #include "hb-test.h" #include "hb-subset-test.h" -#include "hb-subset-serialize.h" +#include "hb-subset.h" char test_gsub_data[106] = "\x0\x1\x0\x0\x0\xa\x0\x1e\x0\x2c\x0\x1\x6c\x61\x74\x6e\x0\x8\x0\x4\x0\x0\x0\x0\xff\xff\x0\x1\x0\x0\x0\x1\x74\x65\x73\x74\x0\x8\x0\x0\x0\x1\x0\x1\x0\x2\x0\x2a\x0\x6\x0\x5\x0\x0\x0\x1\x0\x8\x0\x1\x0\x8\x0\x1\x0\xe\x0\x1\x0\x1\x0\x1\x0\x1\x0\x4\x0\x2\x0\x1\x0\x2\x0\x1\x0\x0\x0\x1\x0\x0\x0\x1\x0\x8\x0\x1\x0\x6\x0\x1\x0\x1\x0\x1\x0\x2"; diff --git a/test/fuzzing/hb-repacker-fuzzer.cc b/test/fuzzing/hb-repacker-fuzzer.cc index f7caeee0f..3f076838d 100644 --- a/test/fuzzing/hb-repacker-fuzzer.cc +++ b/test/fuzzing/hb-repacker-fuzzer.cc @@ -5,7 +5,7 @@ #include #include -#include "hb-subset-serialize.h" +#include "hb-subset.h" typedef struct {