[ot-tags] Fix `min_subtag_len` calculations

This commit is contained in:
David Corbett 2022-05-18 15:05:55 -04:00 committed by Behdad Esfahbod
parent 0b1c2ff96a
commit e3e685e5ee
2 changed files with 6 additions and 9 deletions

View File

@ -1019,14 +1019,12 @@ for initial, items in sorted (complex_tags.items ()):
if not tags:
continue
subtag_len = 0
subtag_len += len(lt.script) if lt.script is not None else 0
subtag_len += len(lt.region) if lt.region is not None else 0
subtag_len += len(lt.variant) if lt.variant is not None else 0
subtag_len += 1 + len (lt.script) if lt.script is not None else 0
subtag_len += 1 + len (lt.region) if lt.region is not None else 0
subtag_len += 1 + len (lt.variant) if lt.variant is not None else 0
min_subtag_len = min(subtag_len, min_subtag_len)
min_subtag_len += 1 # For initial '-'
print (' if (limit - lang_str > %d ||' % min_subtag_len)
print (" (limit - lang_str == %d && *lang_str == '-'))" % min_subtag_len)
print (' if (limit - lang_str >= %d)' % (min_subtag_len + 2))
print (' {')
print (" const char *p = strchr (lang_str, '-');")
print (" if (!p || p >= limit || limit - p < %i) goto out;" % min_subtag_len)
@ -1058,7 +1056,7 @@ for initial, items in sorted (complex_tags.items ()):
print ()
print (' };')
print (' for (i = 0; i < %s && i < *count; i++)' % len (tags))
print (' tags[i] = possible_tags[i];')
print ('\ttags[i] = possible_tags[i];')
print (' *count = i;')
print (' return true;')
print (' }')

View File

@ -1642,8 +1642,7 @@ hb_ot_tags_from_complex_language (const char *lang_str,
unsigned int *count /* IN/OUT */,
hb_tag_t *tags /* OUT */)
{
if (limit - lang_str > 5 ||
(limit - lang_str == 5 && *lang_str == '-'))
if (limit - lang_str >= 7)
{
const char *p = strchr (lang_str, '-');
if (!p || p >= limit || limit - p < 5) goto out;