From cce964cb4f3f29a9addbb079b52c7a712fba93b8 Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Tue, 21 Jul 2026 17:47:36 -0700 Subject: [PATCH] [ot-tag] guard against NULL language in hb_ot_tags_to_script_and_language (#6085) hb_ot_tag_to_language returns NULL for HB_OT_TAG_DEFAULT_LANGUAGE, and hb_language_to_string returns NULL for it, so the script-suffix path called strlen on a NULL pointer whenever the primary script tag did not match the input. Skip the suffix construction when there is no base language string and leave the default (NULL) language in place. Signed-off-by: Sai Asish Y --- src/hb-ot-tag.cc | 4 ++-- test/api/test-ot-tag.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hb-ot-tag.cc b/src/hb-ot-tag.cc index 6ae6c8287..807de522c 100644 --- a/src/hb-ot-tag.cc +++ b/src/hb-ot-tag.cc @@ -668,10 +668,10 @@ hb_ot_tags_to_script_and_language (hb_tag_t script_tag, primary_script_tag, nullptr, nullptr); *language = hb_ot_tag_to_language (language_tag); - if (script_count == 0 || primary_script_tag[0] != script_tag) + const char *lang_str = *language ? hb_language_to_string (*language) : nullptr; + if (lang_str && (script_count == 0 || primary_script_tag[0] != script_tag)) { unsigned char *buf; - const char *lang_str = hb_language_to_string (*language); size_t len = strlen (lang_str); buf = (unsigned char *) hb_malloc (len + 16); if (unlikely (!buf)) diff --git a/test/api/test-ot-tag.c b/test/api/test-ot-tag.c index 60a9c0c0f..e01c169ca 100644 --- a/test/api/test-ot-tag.c +++ b/test/api/test-ot-tag.c @@ -291,6 +291,9 @@ test_ot_tags_to_script_and_language (void) test_tags_to_script_and_language ("dev2", "MAR", "Deva", "mr-x-hbsc-64657632"); test_tags_to_script_and_language ("dev3", "MAR", "Deva", "mr"); test_tags_to_script_and_language ("qaa", "QTZ0", "Qaaa", "x-hbot-51545a30-hbsc-71616120"); + /* Default language tag maps to a NULL language; the script-suffix path + * must not dereference it. */ + test_tags_to_script_and_language ("DFLT", "dflt", "", NULL); } static void