diff --git a/src/autofit/afadjust.c b/src/autofit/afadjust.c index 6637cacfc..a1aa45914 100644 --- a/src/autofit/afadjust.c +++ b/src/autofit/afadjust.c @@ -1405,7 +1405,8 @@ FT_TRACE4(( " " )); idx = HB_SET_VALUE_INVALID; while ( hb( set_next )( gsub_lookups, &idx ) ) - if ( globals->gsub_lookups_single_alternate[idx] ) + if ( idx < globals->gsub_lookup_count && + globals->gsub_lookups_single_alternate[idx] ) { have_idx = TRUE; FT_TRACE4(( " %u", idx )); @@ -1428,9 +1429,17 @@ idx = HB_SET_VALUE_INVALID; while ( hb( set_next )( gsub_lookups, &idx ) ) { - FT_UInt32 offset = globals->gsub_lookups_single_alternate[idx]; + FT_UInt32 offset; + /* HarfBuzz only validates lookup indices while */ + /* processing lookups, not while collecting them, */ + /* so we have to do that by ourselves. */ + if ( idx < globals->gsub_lookup_count ) + offset = globals->gsub_lookups_single_alternate[idx]; + else + offset = 0; + /* Put all substitutions into a single hash table. Note that */ /* the hash values usually contain more than a single character */ /* code; this can happen if different 'SingleSubst' subtables */ diff --git a/src/autofit/afglobal.h b/src/autofit/afglobal.h index 362f56e29..dc0611594 100644 --- a/src/autofit/afglobal.h +++ b/src/autofit/afglobal.h @@ -116,7 +116,9 @@ FT_BEGIN_HEADER /* The GSUB table. */ FT_Byte* gsub; - /* Lookup offsets, with only SingleSubst and AlternateSubst non-NULL. */ + /* An array of lookup offsets (of `gsub_lookup_count` elements), */ + /* with only SingleSubst and AlternateSubst lookups non-NULL. */ + FT_UShort gsub_lookup_count; FT_UInt32* gsub_lookups_single_alternate; #endif diff --git a/src/autofit/afgsub.c b/src/autofit/afgsub.c index f458559d0..a9e3996a7 100644 --- a/src/autofit/afgsub.c +++ b/src/autofit/afgsub.c @@ -364,6 +364,7 @@ } globals->gsub = gsub; + globals->gsub_lookup_count = lookupCount; globals->gsub_lookups_single_alternate = gsub_lookups_single_alternate; return;