[glyf] Charge composite offsets to the work budget (#6410)

* [glyf] Charge composite offsets to the work budget

Composite glyphs prepare component offsets before descending into
children. This work was not charged to the shared rendering budget,
including offsets for children later skipped by cycle detection.
Repeated preparation through COLR extents could time out the shaper.

Charge each offset before loading it and restore the scratch length
on failure. Add a cyclic-composite budget regression and the minimized
fuzzer testcase.

The full Meson suite passes (292 passed, one skipped). The reproducer
completes under ASan/UBSan in 17 seconds instead of timing out after
60 seconds. A failing-allocation variant passes 100 runs.

Fixes: https://oss-fuzz.com/testcase-detail/6193853460447232
Assisted-by: OpenAI Codex

* [glyf] Charge component preparation as traversal work

Component preparation parses records and updates scratch vectors, but
charging one unit per record still allows excessive work within the
shared budget. Use the existing 16-unit glyph traversal charge for
preparing a component, including children skipped by cycle detection.

Increase the cyclic-composite regression's budget so it also catches
the undercharged preparation path. The reproducer now takes about
1.1 seconds under ASan/UBSan and 0.03 seconds in the normal build.

Tested with the full Meson suite (292 passed, one skipped), 100
sanitizer reproducer runs, and 100 failing-allocation variant runs.

Assisted-by: OpenAI Codex
This commit is contained in:
Behdad Esfahbod authored and GitHub committed 2026-10-18 19:54:45 -06:00
1 parent 8abfd0d16e
commit 0bfc7a9b16
3 files changed
+54 -1

No files matched your search

+10 -1
View File
@@ -374,7 +374,16 @@ struct Glyph
case COMPOSITE:
{
for (auto &item : get_composite_iterator ())
if (unlikely (!item.get_points (points, extended))) return false;
{
/* Preparing a component is a traversal step, even if cycle
* detection later skips its child glyph. */
if (unlikely (!hb_budget_spend (*budget, HB_BUDGET_16) ||
!item.get_points (points, extended)))
{
points.resize (old_length);
return false;
}
}
break;
}
case EMPTY:
+44
View File
@@ -1150,6 +1150,49 @@ test_hb_draw_cff_budget (void)
g_assert_cmpint (cff2_blend, >, 512);
}
static void
test_hb_draw_glyf_composite_budget (void)
{
/* A child composite whose 256 components all reference itself. Preparing
* its offsets must consume budget even when cycle detection skips children. */
char glyf_data[16 + 10 + 256 * 6] = {0};
glyf_data[0] = glyf_data[1] = (char) 0xFF;
glyf_data[11] = 0x02;
glyf_data[13] = 0x01;
glyf_data[16] = glyf_data[17] = (char) 0xFF;
for (unsigned i = 0; i < 256; i++)
{
glyf_data[26 + i * 6 + 1] = i < 255 ? 0x22 : 0x02;
glyf_data[26 + i * 6 + 3] = 0x01;
}
const char loca_data[] = {0, 0, 0, 8, 0x03, 0x0D};
hb_face_t *face = hb_face_builder_create ();
HB_FACE_ADD_TABLE (face, "glyf", glyf_data);
HB_FACE_ADD_TABLE (face, "loca", loca_data);
hb_face_set_glyph_count (face, 2);
hb_font_t *font = hb_font_create (face);
draw_budget_data_t data = {HB_BUDGET_DEFAULT, 0};
hb_draw_funcs_t *draw_funcs = hb_draw_funcs_create ();
hb_draw_funcs_set_set_budget_func (draw_funcs, draw_set_budget, NULL, NULL);
hb_draw_funcs_set_get_budget_remaining_func (draw_funcs, draw_get_budget_remaining, NULL, NULL);
g_assert_true (hb_draw_set_budget (draw_funcs, &data, 10000));
g_assert_true (hb_font_draw_glyph_or_fail (font, 0, draw_funcs, &data));
g_assert_true (hb_draw_set_budget (draw_funcs, &data, 2048));
g_assert_false (hb_font_draw_glyph_or_fail (font, 0, draw_funcs, &data));
g_assert_cmpint (data.live, <, 0);
g_assert_true (hb_draw_set_budget (draw_funcs, &data, 10000));
g_assert_true (hb_font_draw_glyph_or_fail (font, 0, draw_funcs, &data));
hb_draw_funcs_destroy (draw_funcs);
hb_font_destroy (font);
hb_face_destroy (face);
}
static void
test_hb_draw_budget (void)
{
@@ -1318,6 +1361,7 @@ main (int argc, char **argv)
hb_test_add (test_hb_draw_immutable);
hb_test_add (test_hb_draw_budget);
hb_test_add (test_hb_draw_cff_budget);
hb_test_add (test_hb_draw_glyf_composite_budget);
const char **font_funcs = hb_font_list_funcs ();
for (const char **font_funcs_name = font_funcs; *font_funcs_name; font_funcs_name++)