From bd306afedb5034e12afad2b8521bc38ee69db2e0 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Wed, 4 Nov 2026 20:02:49 +0200 Subject: [PATCH] [face] Ignore named-instance bits in hb_face_create_or_fail() (#6571) Fixes: https://github.com/harfbuzz/harfbuzz/issues/6567 --- src/hb-face.cc | 2 +- test/api/test-face.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/hb-face.cc b/src/hb-face.cc index 9c2840f21..3187a888e 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -290,7 +290,7 @@ hb_face_create_or_fail (hb_blob_t *blob, unsigned int index) { unsigned num_faces = hb_face_count (blob); - if (index >= num_faces) + if ((index & 0xFFFFu) >= num_faces) return nullptr; hb_face_t *face = hb_face_create (blob, index); diff --git a/test/api/test-face.c b/test/api/test-face.c index 7d27ce5ab..fa7ba9736 100644 --- a/test/api/test-face.c +++ b/test/api/test-face.c @@ -75,6 +75,25 @@ test_create_from_blob_using (const void *user_data) hb_face_destroy (face); } +static void +test_create_or_fail_named_instance_index (void) +{ + hb_blob_t *blob = hb_blob_create_from_file_or_fail (font_file); + g_assert_nonnull (blob); + + unsigned index = face_index | (1u << 16); + hb_face_t *face = hb_face_create_or_fail (blob, index); + g_assert_nonnull (face); + g_assert_cmpuint (hb_face_get_index (face), ==, index); + test_face (face); + hb_face_destroy (face); + + face = hb_face_create_or_fail (blob, hb_face_count (blob) | (1u << 16)); + g_assert_null (face); + + hb_blob_destroy (blob); +} + static void test_default_loader_environment (void) { @@ -124,6 +143,7 @@ main (int argc, char **argv) font_file = hb_test_resolve_path (font_file); + hb_test_add (test_create_or_fail_named_instance_index); hb_test_add (test_default_loader_environment); hb_test_add_flavor ("", test_create_from_file_using); hb_test_add_flavor ("", test_create_from_blob_using);