From 9c093444efb3f215b297b5bf86581dfe7e530448 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Oct 2026 15:26:47 -0600 Subject: [PATCH 1/6] [subset] Honour len in hb_subset_axis_range_from_string() The function documents len as the length of str, but located the ':' separators with strpbrk() and matched "drop" with strcmp(), both of which scan to the next NUL byte. A caller passing an exact-length, non-NUL-terminated slice therefore got an out-of-bounds read, and bytes beyond len could change or reject the parsed range. Bound every scan by str+len: each strpbrk() becomes memchr() bounded by end, the strcmp() becomes a len==4 && hb_memcmp() check, and the empty -piece test !*str becomes str == end. This is the same discipline the sibling parsers hb_feature_from_string()/hb_variation_from_string() already follow. For len == -1 (the only in-tree caller) len becomes strlen() first, so behaviour is unchanged. No public API/ABI change. A regression test in test/api/test-subset.c passes prefixes of longer literals with an explicit len and checks the NUL-terminated cases still parse as before. Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-IL9ZX304. Co-Authored-By: Claude Opus 4.8 --- src/hb-subset-input.cc | 10 +++---- test/api/test-subset.c | 60 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/src/hb-subset-input.cc b/src/hb-subset-input.cc index 00d538117..86849c60d 100644 --- a/src/hb-subset-input.cc +++ b/src/hb-subset-input.cc @@ -627,11 +627,11 @@ hb_subset_axis_range_from_string (const char *str, int len, len = strlen (str); const char *end = str + len; - const char* part = strpbrk (str, ":"); + const char* part = (const char *) memchr (str, ':', end - str); if (!part) { // Single value. - if (strcmp (str, "drop") == 0) + if (len == 4 && 0 == hb_memcmp (str, "drop", 4)) { *axis_min_value = NAN; *axis_def_value = NAN; @@ -652,13 +652,13 @@ hb_subset_axis_range_from_string (const char *str, int len, int count = 0; for (int i = 0; i < 3; i++) { count++; - if (!*str || part == str) + if (str == end || part == str) { values[i] = NAN; if (part == NULL) break; str = part + 1; - part = strpbrk (str, ":"); + part = (const char *) memchr (str, ':', end - str); continue; } @@ -669,7 +669,7 @@ hb_subset_axis_range_from_string (const char *str, int len, if (part == NULL) break; str = part + 1; - part = strpbrk (str, ":"); + part = (const char *) memchr (str, ':', end - str); } if (count == 2) diff --git a/test/api/test-subset.c b/test/api/test-subset.c index 7267741f4..ea1f5c3eb 100644 --- a/test/api/test-subset.c +++ b/test/api/test-subset.c @@ -27,6 +27,8 @@ #include "hb-test.h" #include "hb-subset-test.h" +#include + /* Unit tests for hb-subset-glyf.h */ static void @@ -649,6 +651,63 @@ test_subset_create_for_tables_face_MAXP (void) } #endif +static void +test_subset_axis_range_from_string (void) +{ + float min, max, def; + + /* An explicit len must bound the parse: bytes after len are not part of + * the string and must be neither read nor interpreted. */ + g_assert_true (hb_subset_axis_range_from_string ("100:200:", 3, &min, &max, &def)); + g_assert_cmpfloat (min, ==, 100.f); + g_assert_cmpfloat (def, ==, 100.f); + g_assert_cmpfloat (max, ==, 100.f); + + g_assert_true (hb_subset_axis_range_from_string ("100:200:", 7, &min, &max, &def)); + g_assert_cmpfloat (min, ==, 100.f); + g_assert_true (isnan (def)); + g_assert_cmpfloat (max, ==, 200.f); + + g_assert_true (hb_subset_axis_range_from_string ("100:200,wdth=75:100", 7, &min, &max, &def)); + g_assert_cmpfloat (min, ==, 100.f); + g_assert_true (isnan (def)); + g_assert_cmpfloat (max, ==, 200.f); + + g_assert_true (hb_subset_axis_range_from_string ("100:300:200,", 11, &min, &max, &def)); + g_assert_cmpfloat (min, ==, 100.f); + g_assert_cmpfloat (def, ==, 300.f); + g_assert_cmpfloat (max, ==, 200.f); + + g_assert_true (hb_subset_axis_range_from_string (":300:,", 5, &min, &max, &def)); + g_assert_true (isnan (min)); + g_assert_cmpfloat (def, ==, 300.f); + g_assert_true (isnan (max)); + + g_assert_true (hb_subset_axis_range_from_string ("drop,wdth=75", 4, &min, &max, &def)); + g_assert_true (isnan (min)); + g_assert_true (isnan (def)); + g_assert_true (isnan (max)); + + g_assert_true (hb_subset_axis_range_from_string ("dropped", 4, &min, &max, &def)); + g_assert_true (isnan (min)); + g_assert_false (hb_subset_axis_range_from_string ("dropped", -1, &min, &max, &def)); + g_assert_false (hb_subset_axis_range_from_string ("drop", 3, &min, &max, &def)); + g_assert_false (hb_subset_axis_range_from_string ("", 0, &min, &max, &def)); + + /* NUL-terminated input behaves as before. */ + g_assert_true (hb_subset_axis_range_from_string ("100:200", -1, &min, &max, &def)); + g_assert_cmpfloat (min, ==, 100.f); + g_assert_true (isnan (def)); + g_assert_cmpfloat (max, ==, 200.f); + + g_assert_true (hb_subset_axis_range_from_string ("drop", -1, &min, &max, &def)); + g_assert_true (isnan (min)); + g_assert_true (isnan (def)); + g_assert_true (isnan (max)); + + g_assert_false (hb_subset_axis_range_from_string ("abc", -1, &min, &max, &def)); +} + #ifdef HB_EXPERIMENTAL_API const uint8_t CFF2[226] = { // From https://learn.microsoft.com/en-us/typography/opentype/spec/cff2 @@ -1043,6 +1102,7 @@ main (int argc, char **argv) #ifndef HB_NO_BEYOND_64K hb_test_add (test_subset_create_for_tables_face_MAXP); #endif + hb_test_add (test_subset_axis_range_from_string); #ifdef HB_EXPERIMENTAL_API hb_test_add (test_subset_input_to_string); From db0231fc122d22af7264ef74d87439c36894527c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Oct 2026 15:26:52 -0600 Subject: [PATCH 2/6] [subset] Free the replaced override string in override_name_table() name_table_overrides stores hb_malloc()ed strings as plain hb_bytes_t values, so the invariant that every stored string is freed exactly once in ~hb_subset_input_t broke when set() silently overwrote an existing key: overriding the same name record more than once on one input leaked the previous copy, and so did a NULL (remove) after a non-empty override. hb_subset_input_override_name_table() is the only place that allocates these strings, so fix it there: look the record up with has(&old) and fini() it in place before set() (fini nulls the pair, so no path frees twice, and the lookup happens before set() can reallocate the table). Also free the fresh copy and return false when set() cannot store it, instead of leaking it and returning true. hb_subset_plan_t copies the map and frees its own copies, so it is unaffected. No public API/ABI change. A regression line in test_subset_name_overrides overrides one record twice; only the last string survives and the first must not leak. Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-8SA3SRW4. Co-Authored-By: Claude Opus 4.8 --- src/hb-subset-input.cc | 14 +++++++++++++- test/api/test-subset-nameids.c | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/hb-subset-input.cc b/src/hb-subset-input.cc index 86849c60d..7b4d768ee 100644 --- a/src/hb-subset-input.cc +++ b/src/hb-subset-input.cc @@ -1248,7 +1248,19 @@ hb_subset_input_override_name_table (hb_subset_input_t *input, hb_memcpy (override_name, name_str, str_len); name_bytes = hb_bytes_t (override_name, str_len); } - input->name_table_overrides.set (hb_ot_name_record_ids_t (platform_id, encoding_id, language_id, name_id), name_bytes); + + hb_ot_name_record_ids_t record_ids (platform_id, encoding_id, language_id, name_id); + + /* Overriding the same record again replaces the previous string; free it. */ + hb_bytes_t *old_bytes; + if (input->name_table_overrides.has (record_ids, &old_bytes)) + old_bytes->fini (); + + if (unlikely (!input->name_table_overrides.set (record_ids, name_bytes))) + { + name_bytes.fini (); + return false; + } return true; } #endif diff --git a/test/api/test-subset-nameids.c b/test/api/test-subset-nameids.c index 7fd4f0fd3..b2ef698a5 100644 --- a/test/api/test-subset-nameids.c +++ b/test/api/test-subset-nameids.c @@ -86,6 +86,8 @@ test_subset_name_overrides (void) hb_set_add_range (name_ids, 0, 13); hb_subset_input_t *subset_input = hb_subset_test_create_input_from_nameids (name_ids); + /* Override the same record twice; only the last string must survive (and the first must not leak). */ + hb_subset_input_override_name_table (subset_input, 1, 1, 0, 0, "Roboto Replaced", -1); hb_subset_input_override_name_table (subset_input, 1, 1, 0, 0, str1, -1); hb_subset_input_override_name_table (subset_input, 1, 3, 1, 0x409, str1_3, -1); hb_subset_input_override_name_table (subset_input, 2, 1, 0, 0, str2, 4); From 8f09a11184c2bc151b396c9c8342aaf1e15e60a1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Oct 2026 15:27:31 -0600 Subject: [PATCH 3/6] [face-builder] Limit builder faces to 65535 tables A builder face must always be serializable into an sfnt, but hb_face_builder_add_table() accepted any number of tables while the table directory's numTables is 16-bit. Serializing a 65536th table hit the assert in BinSearchHeader::operator= (or, with NDEBUG, truncated the count and then looped forever through hb_face_reference_blob()'s retry). The subsetter reaches this with HB_SUBSET_FLAGS_PASSTHROUGH_UNRECOGNIZED because glyf::subset() always adds a 'loca' the source need not have. Enforce the limit where tables are added, so the subsetter fails cleanly at plan->add_table() and a builder face can always be written out; replacing an existing tag is still allowed. Also stop hb_face_reference_blob() from recursing into itself on the fallback builder it just built (serialize it directly with reference_table()): otherwise a builder that cannot produce a blob is retried without end. A regression test in test/api/test-get-table-tags.c adds 65535 tags, checks the 65536th is refused, that replacement still works, and that the serialized blob has the expected size. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-7BXQZ7HS. Co-Authored-By: Claude Opus 4.8 --- src/hb-face-builder.cc | 8 +++++++- src/hb-face.cc | 4 +++- test/api/test-get-table-tags.c | 23 +++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/hb-face-builder.cc b/src/hb-face-builder.cc index cb55e4b8f..d58b6b4fe 100644 --- a/src/hb-face-builder.cc +++ b/src/hb-face-builder.cc @@ -234,7 +234,8 @@ hb_face_builder_create () * @blob: The blob containing the table data to add * * Add table for @tag with data provided by @blob to the face. @face must - * be created using hb_face_builder_create(). + * be created using hb_face_builder_create(). A face can hold at most + * 65535 tables; adding more fails. * * Since: 1.9.0 **/ @@ -249,6 +250,11 @@ hb_face_builder_add_table (hb_face_t *face, hb_tag_t tag, hb_blob_t *blob) hb_face_builder_data_t *data = (hb_face_builder_data_t *) face->user_data; + /* numTables in the font file's table directory is 16bit. */ + if (unlikely (data->tables.get_population () >= 0xFFFFu && + !data->tables.has (tag))) + return false; + hb_blob_t* previous = data->tables.get (tag).data; if (!data->tables.set (tag, face_table_info_t {hb_blob_reference (blob), (unsigned) -1})) { diff --git a/src/hb-face.cc b/src/hb-face.cc index ee633a624..badf5d9c3 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -745,7 +745,9 @@ hb_face_reference_blob (hb_face_t *face) } } - blob = hb_face_reference_blob (builder); + // Serialize the builder directly; going through hb_face_reference_blob() + // again would recurse if the builder cannot produce a blob either. + blob = builder->reference_table (HB_TAG_NONE); hb_face_destroy (builder); } } diff --git a/test/api/test-get-table-tags.c b/test/api/test-get-table-tags.c index e941d588a..b417f0094 100644 --- a/test/api/test-get-table-tags.c +++ b/test/api/test-get-table-tags.c @@ -98,6 +98,28 @@ test_get_table_tags_builder (void) hb_face_destroy (face); } +static void +test_get_table_tags_builder_limit (void) +{ + /* A font file's table directory cannot hold more than 65535 tables. */ + hb_face_t *face = hb_face_builder_create (); + hb_blob_t *blob = hb_blob_create ("test", 4, HB_MEMORY_MODE_READONLY, NULL, NULL); + + for (unsigned i = 1; i <= 0xFFFFu; i++) + g_assert_true (hb_face_builder_add_table (face, i, blob)); + g_assert_false (hb_face_builder_add_table (face, 0x10000u, blob)); + /* Replacing a table is still fine. */ + g_assert_true (hb_face_builder_add_table (face, 1, blob)); + g_assert_cmpuint (0xFFFFu, ==, hb_face_get_table_tags (face, 0, NULL, NULL)); + + hb_blob_t *file = hb_face_reference_blob (face); + g_assert_cmpuint (12 + 0xFFFFu * (16 + 4), ==, hb_blob_get_length (file)); + + hb_blob_destroy (file); + hb_blob_destroy (blob); + hb_face_destroy (face); +} + #ifdef HAVE_FREETYPE static void test_get_table_tags_ft (void) @@ -231,6 +253,7 @@ main (int argc, char **argv) hb_test_add (test_get_table_tags_default); hb_test_add (test_get_table_tags_builder); + hb_test_add (test_get_table_tags_builder_limit); #ifdef HAVE_FREETYPE hb_test_add (test_get_table_tags_ft); hb_test_add (test_get_table_tags_ft_stream); From dae0a46b4db6da2e5f233cea5dd52d4c8e53dc22 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Oct 2026 15:28:07 -0600 Subject: [PATCH 4/6] [face-builder] Bound the summed table length before allocating the blob Table records of a font file may overlap, so the sum of the passed -through table lengths is not bounded by the size of the font: with HB_SUBSET_FLAGS_PASSTHROUGH_UNRECOGNIZED a 262 KB font of aliased records made _hb_face_builder_data_reference_blob() allocate and fill a ~4 GiB buffer, only for hb_blob_create() to refuse it. Accumulate face_length with hb_unsigned_add_overflows() and return nullptr as soon as the total reaches 1u<<31, the length hb_blob_create_or_fail() refuses, so the 2-4 GiB allocate-fill-free cycle no longer happens; the serializer's own bounds already prevented any overrun once the sum wrapped. Output for every input that succeeded before is unchanged. The endless retry that turned this into a hang is fixed in the companion commit (hb_face_reference_blob() no longer recurses into itself on the fallback builder). Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-NCMHVO1A. Co-Authored-By: Claude Opus 4.8 --- src/hb-face-builder.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/hb-face-builder.cc b/src/hb-face-builder.cc index d58b6b4fe..e4b232b8d 100644 --- a/src/hb-face-builder.cc +++ b/src/hb-face-builder.cc @@ -99,7 +99,16 @@ _hb_face_builder_data_reference_blob (hb_face_builder_data_t *data) unsigned int face_length = table_count * 16 + 12; for (auto info : data->tables.values()) - face_length += hb_ceil_to_4 (hb_blob_get_length (info.data)); + if (unlikely (hb_unsigned_add_overflows (face_length, + hb_ceil_to_4 (hb_blob_get_length (info.data)), + &face_length))) + return nullptr; + + /* hb_blob_create() refuses such a length; do not assemble the font + * only to throw it away. Tables referenced from a font file can + * overlap in it, so the sum is not bounded by the size of that file. */ + if (unlikely (face_length >= 1u << 31)) + return nullptr; char *buf = (char *) hb_malloc (face_length); if (unlikely (!buf)) From d52c540c7a063a8ef502ce0be46d3e5a3ce6d2a7 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Oct 2026 15:30:37 -0600 Subject: [PATCH 5/6] [face-builder] Keep table tags sorted at add_table() time _hb_face_builder_get_table_tags() copied every key out of the hash map and qsort()ed it on each call, so a caller paging through the list (the subsetter uses 32-entry pages in hb_subset_plan_execute_or_fail() and _is_table_present()) paid N/32 sorts of N tags per enumeration. With the 65535-table face that hb_subset_preprocess() hands back this was ~25 s of CPU per hb_subset_or_fail() call. Keep an hb_vector_t next to the map and maintain it in hb_face_builder_add_table(), the only place keys are inserted: a binary search finds the slot, the vector is pre-allocated before the map is touched so an allocation failure leaves both structures unchanged, and the slot is opened with the same resize+memmove idiom hb-bit-set.hh uses. The getter becomes a sub_array() copy, so enumeration is O(page) and the returned order is unchanged. _hb_face_builder_data_reference_blob() keeps its own sort, which orders by blob size, not by tag. A regression test adds tags out of order, one of them twice, and checks that paging with a 4-entry array returns each tag once in ascending order. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-VENZFNXH. Co-Authored-By: Claude Opus 4.8 --- src/hb-face-builder.cc | 41 +++++++++++++++++++---------- test/api/test-get-table-tags.c | 48 ++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 14 deletions(-) diff --git a/src/hb-face-builder.cc b/src/hb-face-builder.cc index e4b232b8d..7e0c1fb72 100644 --- a/src/hb-face-builder.cc +++ b/src/hb-face-builder.cc @@ -48,6 +48,7 @@ struct face_table_info_t struct hb_face_builder_data_t { hb_hashmap_t tables; + hb_vector_t sorted_tags; /* Keys of tables, kept sorted. */ }; static int compare_entries (const void* pa, const void* pb) @@ -74,6 +75,7 @@ _hb_face_builder_data_create () return nullptr; data->tables.init (); + data->sorted_tags.init (); return data; } @@ -87,6 +89,7 @@ _hb_face_builder_data_destroy (void *user_data) hb_blob_destroy (info.data); data->tables.fini (); + data->sorted_tags.fini (); hb_free (data); } @@ -182,18 +185,8 @@ _hb_face_builder_get_table_tags (const hb_face_t *face HB_UNUSED, return population; } - // Sort the tags. - hb_vector_t sorted_tags; - data->tables.keys () | hb_sink (sorted_tags); - if (unlikely (sorted_tags.in_error ())) - { - // Not much to do... - } - sorted_tags.qsort ([] (const hb_tag_t &a, const hb_tag_t &b) { - return (a > b) - (a < b); - }); - - auto array = sorted_tags.as_array ().sub_array (start_offset, table_count); + // Tags are kept sorted by hb_face_builder_add_table(). + auto array = data->sorted_tags.as_array ().sub_array (start_offset, table_count); if (table_tags) { auto out = hb_array (table_tags, *table_count); @@ -259,9 +252,20 @@ hb_face_builder_add_table (hb_face_t *face, hb_tag_t tag, hb_blob_t *blob) hb_face_builder_data_t *data = (hb_face_builder_data_t *) face->user_data; + // Keep the tags sorted here, such that get_table_tags() does not + // have to sort them on every call. + auto &sorted_tags = data->sorted_tags; + unsigned i; + bool is_new = !hb_bsearch_impl (&i, tag, + sorted_tags.arrayZ, sorted_tags.length, + sizeof (hb_tag_t), + _hb_cmp_operator); + /* numTables in the font file's table directory is 16bit. */ - if (unlikely (data->tables.get_population () >= 0xFFFFu && - !data->tables.has (tag))) + if (unlikely (is_new && data->tables.get_population () >= 0xFFFFu)) + return false; + + if (is_new && unlikely (!sorted_tags.alloc (sorted_tags.length + 1))) return false; hb_blob_t* previous = data->tables.get (tag).data; @@ -271,6 +275,15 @@ hb_face_builder_add_table (hb_face_t *face, hb_tag_t tag, hb_blob_t *blob) return false; } + if (is_new) + { + sorted_tags.resize (sorted_tags.length + 1); // Cannot fail; allocated above. + memmove (sorted_tags.arrayZ + i + 1, + sorted_tags.arrayZ + i, + (sorted_tags.length - 1 - i) * sorted_tags.item_size); + sorted_tags.arrayZ[i] = tag; + } + hb_blob_destroy (previous); return true; } diff --git a/test/api/test-get-table-tags.c b/test/api/test-get-table-tags.c index b417f0094..2fb1f2fd2 100644 --- a/test/api/test-get-table-tags.c +++ b/test/api/test-get-table-tags.c @@ -120,6 +120,53 @@ test_get_table_tags_builder_limit (void) hb_face_destroy (face); } +static void +test_get_table_tags_builder_unsorted (void) +{ + /* Tags added out of order, one of them twice; must come back + * sorted, each once, with any page size. */ + static const hb_tag_t added[] = { + HB_TAG ('m','a','x','p'), + HB_TAG ('G','S','U','B'), + HB_TAG ('h','e','a','d'), + HB_TAG ('z','z','z','z'), + HB_TAG ('h','e','a','d'), + HB_TAG ('c','m','a','p'), + HB_TAG ('G','D','E','F'), + }; + static const hb_tag_t expected[] = { + HB_TAG ('G','D','E','F'), + HB_TAG ('G','S','U','B'), + HB_TAG ('c','m','a','p'), + HB_TAG ('h','e','a','d'), + HB_TAG ('m','a','x','p'), + HB_TAG ('z','z','z','z'), + }; + const unsigned num_expected = sizeof (expected) / sizeof (expected[0]); + + hb_face_t *face = hb_face_builder_create (); + hb_blob_t *blob = hb_blob_create ("test", 4, HB_MEMORY_MODE_READONLY, NULL, NULL); + for (unsigned i = 0; i < sizeof (added) / sizeof (added[0]); i++) + g_assert_true (hb_face_builder_add_table (face, added[i], blob)); + hb_blob_destroy (blob); + + g_assert_cmpuint (num_expected, ==, hb_face_get_table_tags (face, 0, NULL, NULL)); + + hb_tag_t tags[4]; + unsigned offset = 0, count = sizeof (tags) / sizeof (tags[0]); + while (((void) hb_face_get_table_tags (face, offset, &count, tags), count)) + { + g_assert_cmpuint (offset + count, <=, num_expected); + for (unsigned i = 0; i < count; i++) + g_assert_cmpuint (tags[i], ==, expected[offset + i]); + offset += count; + count = sizeof (tags) / sizeof (tags[0]); + } + g_assert_cmpuint (offset, ==, num_expected); + + hb_face_destroy (face); +} + #ifdef HAVE_FREETYPE static void test_get_table_tags_ft (void) @@ -254,6 +301,7 @@ main (int argc, char **argv) hb_test_add (test_get_table_tags_default); hb_test_add (test_get_table_tags_builder); hb_test_add (test_get_table_tags_builder_limit); + hb_test_add (test_get_table_tags_builder_unsorted); #ifdef HAVE_FREETYPE hb_test_add (test_get_table_tags_ft); hb_test_add (test_get_table_tags_ft_stream); From a5235968bb1b10ee805369529792809fca850de1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Oct 2026 15:35:53 -0600 Subject: [PATCH 6/6] [subset] Collect lookup-variation feature indices once in dedup _GSUBGPOS_find_duplicate_features() compared every pair of same-tag retained features and, for each pair, called FeatureVariations::has_lookup_variations() twice -- a linear walk of the FeatureVariations 1.1 LookupVariationRecord array -- so a font cost features^2 x records with no work limit (31 s for a 144 KB font). The FeatureVariationRecord half of the same question is already answered once up front via collect_feature_indices() into the variable_features set, so do the same for the LookupVariationRecord half: has_lookup_variations() becomes collect_lookup_variation_feature_indices(), called once before the loop, and the per-pair test only consults the set. It is collected regardless of all_axes_pinned because the old code consulted the records in both cases, so dedup decisions are unchanged for fonts with sorted records; the only behavioural difference is that a record sitting after one with a larger featureIndex (which the old early break skipped) now also keeps its feature distinct, which is the conservative direction. has_lookup_variations() had no other callers. The remaining F^2/2 same-tag pair loop is pre-existing and not part of this finding. A timing-only regression font is added under test/fuzzing/fonts/. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-Z3B8ASPA. Co-Authored-By: Claude Opus 4.8 --- src/hb-ot-layout-common.hh | 10 ++-------- src/hb-subset-plan-layout.cc | 6 +++--- ...b-lookup-variation-feature-dedup-timeout.ttf | Bin 0 -> 46332 bytes 3 files changed, 5 insertions(+), 11 deletions(-) create mode 100644 test/fuzzing/fonts/gsub-lookup-variation-feature-dedup-timeout.ttf diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index c13fab3bd..32142607b 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -6092,16 +6092,10 @@ struct FeatureVariations (this+record.substitutions).collect_feature_indices (feature_indices); } - bool has_lookup_variations (unsigned feature_index) const + void collect_lookup_variation_feature_indices (hb_set_t *feature_indices) const { for (const LookupVariationRecord &record : get_lookup_variation_records ()) - { - if (record.featureIndex == feature_index) - return true; - if (record.featureIndex > feature_index) - break; - } - return false; + feature_indices->add (record.featureIndex); } bool subset (hb_subset_context_t *c, diff --git a/src/hb-subset-plan-layout.cc b/src/hb-subset-plan-layout.cc index a2a963335..223c90e9e 100644 --- a/src/hb-subset-plan-layout.cc +++ b/src/hb-subset-plan-layout.cc @@ -295,6 +295,8 @@ _GSUBGPOS_find_duplicate_features (const OT::GSUBGPOS &g, hb_set_t variable_features; if (!all_axes_pinned) g.get_feature_variations ().collect_feature_indices (&variable_features); + /* Lookup variations are instanced, not dropped, when all axes are pinned. */ + g.get_feature_variations ().collect_lookup_variation_feature_indices (&variable_features); if (unlikely (variable_features.in_error ())) return; #endif hb_hashmap_t> unique_features; @@ -320,9 +322,7 @@ _GSUBGPOS_find_duplicate_features (const OT::GSUBGPOS &g, { #ifndef HB_NO_VAR /* Matching base lookups do not imply matching alternate behavior. */ - if (variable_features.has (i) || variable_features.has (other_f_index) || - g.get_feature_variations ().has_lookup_variations (i) || - g.get_feature_variations ().has_lookup_variations (other_f_index)) + if (variable_features.has (i) || variable_features.has (other_f_index)) continue; #endif diff --git a/test/fuzzing/fonts/gsub-lookup-variation-feature-dedup-timeout.ttf b/test/fuzzing/fonts/gsub-lookup-variation-feature-dedup-timeout.ttf new file mode 100644 index 0000000000000000000000000000000000000000..9cc9a96f1c904d8bb1ee93a4d2f87f6a6f42524e GIT binary patch literal 46332 zcmeI*X;jtKyTI}1c{V92;yfWLA|fi1sS!Eg5aC3IW9B@d;+QEZIZv4xInSDzIcH`{ zibF<g2efICL-+UJ@VC{X@5fza< zzNhceq)ofV|GbicB3o|v8q{ORKl9A)zA-wrcaM~R=NY~+Hr03I-+7L2j7S}nmj3Vj zs&5P$)Fb^r>u>w!c|?6zaNe7-xgzmdq6vvfZ6#0w{A(UQbpACeCeC-~5#LYe^}Y9~ zyVMna{ml#}ujCKV)HDoTV@l1Qm6QBp;! zN;Qd=>JlT5Ney{iYDz7sEl)_SJSlPVl+=;BQcvnjyfl!8(nuQ1(~=<1NTM{6rqWEB zOAASoXQib)C&|)ET1y*gEA6DcJTD#O1?ecAq_cF9uF_4qOAqNOy(C3?OCRYgsnSpS z%K%@^K{8lglp*qx43%M$CNIly86oNNij0&|GFrySSQ#hdWr9qUNitbpl_~O?OqJJV zn!F(y@}^9e88TC5$!wV;b7h{)mj$v=7Rh2+B1`2hStf7Ga(PEq$h)#qR>^8vBWq=y zte5v>gS;;r~GCmi#8S<#)Lwf5=_=Q|`%Ma$o+I2lCMO>!E7uG(aEGJepSn z^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