From bc678801ce4be8e83c5b7c013fca805ea71a38e4 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 8 Sep 2026 12:14:02 -0600 Subject: [PATCH] [subset] Emit a valid empty shared-tuples offset (#6240) When a gvar table has no shared tuples, point sharedTuplesOffset at the end of the glyph-variation offsets array, where the empty shared-tuples array resides, instead of emitting a null offset. This lets strict consumers retain glyph variations in partially instantiated fonts with no shared tuples. Assisted-by: OpenAI Codex --- src/hb-ot-var-gvar-table.hh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index f5ba7c9aa..10b5f54eb 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -379,7 +379,8 @@ struct gvar_GVAR bool long_offset = glyph_var_data_size > 0x1FFFEu || force_long_offsets; out->flags = long_offset ? 1 : 0; - HBUINT8 *glyph_var_data_offsets = c->allocate_size ((long_offset ? 4 : 2) * (num_glyphs + 1), false); + unsigned glyph_var_data_offsets_size = (long_offset ? 4 : 2) * (num_glyphs + 1); + HBUINT8 *glyph_var_data_offsets = c->allocate_size (glyph_var_data_offsets_size, false); if (!glyph_var_data_offsets) return_trace (false); /* shared tuples */ @@ -387,7 +388,7 @@ struct gvar_GVAR out->sharedTupleCount = shared_tuple_count; if (!shared_tuple_count) - out->sharedTuples = 0; + out->sharedTuples = (char *) glyph_var_data_offsets + glyph_var_data_offsets_size - (char *) out; else { hb_array_t shared_tuples = glyph_vars.compiled_shared_tuples.as_array ().copy (c); @@ -507,12 +508,13 @@ struct gvar_GVAR #endif out->flags = long_offset ? 1 : 0; - HBUINT8 *subset_offsets = c->serializer->allocate_size ((long_offset ? 4 : 2) * (num_glyphs + 1), false); + unsigned subset_offsets_size = (long_offset ? 4 : 2) * (num_glyphs + 1); + HBUINT8 *subset_offsets = c->serializer->allocate_size (subset_offsets_size, false); if (!subset_offsets) return_trace (false); /* shared tuples */ if (!sharedTupleCount || !sharedTuples) - out->sharedTuples = 0; + out->sharedTuples = (char *) subset_offsets + subset_offsets_size - (char *) out; else { unsigned int shared_tuple_size = F2DOT14::static_size * axisCount * sharedTupleCount;