diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index a85ad6d4d..5279d91d8 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -1164,7 +1164,7 @@ struct Chain #ifndef HB_NO_AAT else if (type == HB_AAT_LAYOUT_FEATURE_TYPE_LANGUAGE_TAG_TYPE && setting && /* TODO: Rudimentary language matching. */ - hb_language_matches (map->face->table.ltag->get_language (setting - 1), map->props.language)) + map->face->table.ltag->matches_language (setting - 1, map->props.language)) { flags &= feature.disableFlags; flags |= feature.enableFlags; diff --git a/src/hb-aat-ltag-table.hh b/src/hb-aat-ltag-table.hh index c974025d4..6dc69b0e8 100644 --- a/src/hb-aat-ltag-table.hh +++ b/src/hb-aat-ltag-table.hh @@ -71,6 +71,32 @@ struct ltag range.length); } + /* Equivalent to hb_language_matches (get_language (i), specific), but + * without interning the font's tag: hb_language_from_string() appends + * every new string to a process-wide, linearly-searched, never-freed list, + * so a hostile font with many tags and many feature records referencing + * them could make that quadratic. */ + bool matches_language (unsigned int i, hb_language_t specific) const + { + const char *s = hb_language_to_string (specific); + if (!s) return false; + + const FTStringRange &range = tagRanges[i]; + const HBUINT8 *tag = (this+range.tag).arrayZ; + /* Canonicalize the same way hb_language_from_string() does: at most 63 + * bytes, lowercase, '_' to '-', stop at the first other non-alphanumeric. */ + unsigned len = hb_min ((unsigned) range.length, 63u); + unsigned l = 0; + for (; l < len; l++) + { + unsigned char c = TOLOWER (tag[l]); + if (c == '_') c = '-'; + if (!ISALNUM (c) && c != '-') break; + if (c != (unsigned char) s[l]) return false; + } + return l && (s[l] == '\0' || s[l] == '-'); + } + bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); diff --git a/test/shape/data/in-house/fonts/882a555639995ed746c7575416acb689ecb9549d.ttf b/test/shape/data/in-house/fonts/882a555639995ed746c7575416acb689ecb9549d.ttf new file mode 100644 index 000000000..c3f0d5311 Binary files /dev/null and b/test/shape/data/in-house/fonts/882a555639995ed746c7575416acb689ecb9549d.ttf differ diff --git a/test/shape/data/in-house/tests/aat-morx.tests b/test/shape/data/in-house/tests/aat-morx.tests index 2673c9627..100c646e4 100644 --- a/test/shape/data/in-house/tests/aat-morx.tests +++ b/test/shape/data/in-house/tests/aat-morx.tests @@ -6,3 +6,12 @@ ../fonts/7fb6608532fe39dd993eb3fc74e84256bd2d547e.ttf;--font-funcs=ot --no-glyph-names --no-positions --no-clusters;U+0061,U+0062;[2|2] ../fonts/7fb6608532fe39dd993eb3fc74e84256bd2d547e.ttf;--font-funcs=ot --no-glyph-names --no-positions --no-clusters;U+0061,U+0062,U+0063;[2|2|1] ../fonts/3503b8963831c2381809884633f483b7361baa97.ttf;--font-funcs=ot;U+0062,U+0062,U+0062,U+0062;[gid3=0+500|gid3=1+500|gid3=2+500|gid3=3+500] +../fonts/882a555639995ed746c7575416acb689ecb9549d.ttf;--language=sr;U+0041;[gid2=0+600] +../fonts/882a555639995ed746c7575416acb689ecb9549d.ttf;--language=SR;U+0041;[gid2=0+600] +../fonts/882a555639995ed746c7575416acb689ecb9549d.ttf;--language=sr-Latn-RS;U+0041;[gid2=0+600] +../fonts/882a555639995ed746c7575416acb689ecb9549d.ttf;--language=srb;U+0041;[gid1=0+600] +../fonts/882a555639995ed746c7575416acb689ecb9549d.ttf;--language=s;U+0041;[gid1=0+600] +../fonts/882a555639995ed746c7575416acb689ecb9549d.ttf;--language=en;U+0041;[gid1=0+600] +../fonts/882a555639995ed746c7575416acb689ecb9549d.ttf;--language=zh-hant;U+0041;[gid3=0+600] +../fonts/882a555639995ed746c7575416acb689ecb9549d.ttf;--language=ZH_HANT;U+0041;[gid3=0+600] +../fonts/882a555639995ed746c7575416acb689ecb9549d.ttf;--language=zh;U+0041;[gid1=0+600]