mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-24 16:31:14 +01:00
[aat] Match morx language-tag features against ltag without interning the font's tags
Chain::compile_flags() resolved every type-39 (language tag) feature record by interning the font's ltag string with hb_language_from_string(), whose process-wide language list is a linear, never-freed linked list meant for the handful of languages an application passes in. A font controls both the number of records and the number of distinct tags, so shape-plan creation became quadratic (about a minute for a 125 KB font) and the tags stayed in the list for the life of the process. Add ltag::matches_language(i, specific), which compares the tag bytes directly against the buffer language, applying the same canonicalization hb_language_from_string() does (at most 63 bytes, lowercase, '_' to '-', stop at the first other non-alphanumeric) and the same prefix rule as hb_language_matches(); each record now costs at most the length of the buffer's language and nothing is added to the global list. get_language() is kept for the name table, which genuinely needs an hb_language_t. Behaviour is unchanged for every real tag; only a degenerate tag with no valid leading byte, which used to become the empty/invalid language, now matches nothing. Adds a regression font to the in-house aat-morx tests whose type-39 features gate substitutions by tags 'sr' and 'Zh_Hant', exercising case folding, '_' canonicalization, subtag prefix matching and non-matches. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-KYZIZMO6. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
77be62a733
commit
cd570b6f54
4 files changed
+36
-1
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Binary file not shown.
@@ -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]
|
||||
Reference in new issue
Block a user