diff options
Diffstat (limited to 'src/3rdparty/harfbuzz-ng/src/hb-ot-layout-gsub-table.hh')
-rw-r--r-- | src/3rdparty/harfbuzz-ng/src/hb-ot-layout-gsub-table.hh | 102 |
1 files changed, 49 insertions, 53 deletions
diff --git a/src/3rdparty/harfbuzz-ng/src/hb-ot-layout-gsub-table.hh b/src/3rdparty/harfbuzz-ng/src/hb-ot-layout-gsub-table.hh index 66fcb3f3af..0b09c4e4a1 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-ot-layout-gsub-table.hh +++ b/src/3rdparty/harfbuzz-ng/src/hb-ot-layout-gsub-table.hh @@ -44,7 +44,7 @@ struct SingleSubstFormat1 for (iter.init (this+coverage); iter.more (); iter.next ()) { /* TODO Switch to range-based API to work around malicious fonts. - * https://github.com/behdad/harfbuzz/issues/363 */ + * https://github.com/harfbuzz/harfbuzz/issues/363 */ hb_codepoint_t glyph_id = iter.get_glyph (); if (c->glyphs->has (glyph_id)) c->glyphs->add ((glyph_id + deltaGlyphID) & 0xFFFFu); @@ -54,13 +54,13 @@ struct SingleSubstFormat1 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const { TRACE_COLLECT_GLYPHS (this); + if (unlikely (!(this+coverage).add_coverage (c->input))) return; Coverage::Iter iter; for (iter.init (this+coverage); iter.more (); iter.next ()) { /* TODO Switch to range-based API to work around malicious fonts. - * https://github.com/behdad/harfbuzz/issues/363 */ + * https://github.com/harfbuzz/harfbuzz/issues/363 */ hb_codepoint_t glyph_id = iter.get_glyph (); - c->input->add (glyph_id); c->output->add ((glyph_id + deltaGlyphID) & 0xFFFFu); } } @@ -110,11 +110,11 @@ struct SingleSubstFormat1 } protected: - USHORT format; /* Format identifier--format = 1 */ + UINT16 format; /* Format identifier--format = 1 */ OffsetTo<Coverage> coverage; /* Offset to Coverage table--from * beginning of Substitution table */ - SHORT deltaGlyphID; /* Add to original GlyphID to get + INT16 deltaGlyphID; /* Add to original GlyphID to get * substitute GlyphID */ public: DEFINE_SIZE_STATIC (6); @@ -130,7 +130,7 @@ struct SingleSubstFormat2 for (iter.init (this+coverage); iter.more (); iter.next ()) { if (unlikely (iter.get_coverage () >= count)) - break; /* Work around malicious fonts. https://github.com/behdad/harfbuzz/issues/363 */ + break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */ if (c->glyphs->has (iter.get_glyph ())) c->glyphs->add (substitute[iter.get_coverage ()]); } @@ -139,13 +139,13 @@ struct SingleSubstFormat2 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const { TRACE_COLLECT_GLYPHS (this); + if (unlikely (!(this+coverage).add_coverage (c->input))) return; Coverage::Iter iter; unsigned int count = substitute.len; for (iter.init (this+coverage); iter.more (); iter.next ()) { if (unlikely (iter.get_coverage () >= count)) - break; /* Work around malicious fonts. https://github.com/behdad/harfbuzz/issues/363 */ - c->input->add (iter.get_glyph ()); + break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */ c->output->add (substitute[iter.get_coverage ()]); } } @@ -195,7 +195,7 @@ struct SingleSubstFormat2 } protected: - USHORT format; /* Format identifier--format = 2 */ + UINT16 format; /* Format identifier--format = 2 */ OffsetTo<Coverage> coverage; /* Offset to Coverage table--from * beginning of Substitution table */ @@ -249,7 +249,7 @@ struct SingleSubst protected: union { - USHORT format; /* Format identifier */ + UINT16 format; /* Format identifier */ SingleSubstFormat1 format1; SingleSubstFormat2 format2; } u; @@ -269,9 +269,7 @@ struct Sequence inline void collect_glyphs (hb_collect_glyphs_context_t *c) const { TRACE_COLLECT_GLYPHS (this); - unsigned int count = substitute.len; - for (unsigned int i = 0; i < count; i++) - c->output->add (substitute[i]); + c->output->add_array (substitute.array, substitute.len); } inline bool apply (hb_apply_context_t *c) const @@ -287,7 +285,7 @@ struct Sequence return_trace (true); } /* Spec disallows this, but Uniscribe allows it. - * https://github.com/behdad/harfbuzz/issues/253 */ + * https://github.com/harfbuzz/harfbuzz/issues/253 */ else if (unlikely (count == 0)) { c->buffer->delete_glyph (); @@ -339,7 +337,7 @@ struct MultipleSubstFormat1 for (iter.init (this+coverage); iter.more (); iter.next ()) { if (unlikely (iter.get_coverage () >= count)) - break; /* Work around malicious fonts. https://github.com/behdad/harfbuzz/issues/363 */ + break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */ if (c->glyphs->has (iter.get_glyph ())) (this+sequence[iter.get_coverage ()]).closure (c); } @@ -348,7 +346,7 @@ struct MultipleSubstFormat1 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const { TRACE_COLLECT_GLYPHS (this); - (this+coverage).add_coverage (c->input); + if (unlikely (!(this+coverage).add_coverage (c->input))) return; unsigned int count = sequence.len; for (unsigned int i = 0; i < count; i++) (this+sequence[i]).collect_glyphs (c); @@ -400,7 +398,7 @@ struct MultipleSubstFormat1 } protected: - USHORT format; /* Format identifier--format = 1 */ + UINT16 format; /* Format identifier--format = 1 */ OffsetTo<Coverage> coverage; /* Offset to Coverage table--from * beginning of Substitution table */ @@ -442,7 +440,7 @@ struct MultipleSubst protected: union { - USHORT format; /* Format identifier */ + UINT16 format; /* Format identifier */ MultipleSubstFormat1 format1; } u; }; @@ -461,7 +459,7 @@ struct AlternateSubstFormat1 for (iter.init (this+coverage); iter.more (); iter.next ()) { if (unlikely (iter.get_coverage () >= count)) - break; /* Work around malicious fonts. https://github.com/behdad/harfbuzz/issues/363 */ + break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */ if (c->glyphs->has (iter.get_glyph ())) { const AlternateSet &alt_set = this+alternateSet[iter.get_coverage ()]; unsigned int count = alt_set.len; @@ -474,17 +472,15 @@ struct AlternateSubstFormat1 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const { TRACE_COLLECT_GLYPHS (this); + if (unlikely (!(this+coverage).add_coverage (c->input))) return; Coverage::Iter iter; unsigned int count = alternateSet.len; for (iter.init (this+coverage); iter.more (); iter.next ()) { if (unlikely (iter.get_coverage () >= count)) - break; /* Work around malicious fonts. https://github.com/behdad/harfbuzz/issues/363 */ - c->input->add (iter.get_glyph ()); + break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */ const AlternateSet &alt_set = this+alternateSet[iter.get_coverage ()]; - unsigned int count = alt_set.len; - for (unsigned int i = 0; i < count; i++) - c->output->add (alt_set[i]); + c->output->add_array (alt_set.array, alt_set.len); } } @@ -552,7 +548,7 @@ struct AlternateSubstFormat1 } protected: - USHORT format; /* Format identifier--format = 1 */ + UINT16 format; /* Format identifier--format = 1 */ OffsetTo<Coverage> coverage; /* Offset to Coverage table--from * beginning of Substitution table */ @@ -594,7 +590,7 @@ struct AlternateSubst protected: union { - USHORT format; /* Format identifier */ + UINT16 format; /* Format identifier */ AlternateSubstFormat1 format1; } u; }; @@ -615,9 +611,7 @@ struct Ligature inline void collect_glyphs (hb_collect_glyphs_context_t *c) const { TRACE_COLLECT_GLYPHS (this); - unsigned int count = component.len; - for (unsigned int i = 1; i < count; i++) - c->input->add (component[i]); + c->input->add_array (component.array, component.len ? component.len - 1 : 0); c->output->add (ligGlyph); } @@ -658,7 +652,7 @@ struct Ligature if (likely (!match_input (c, count, &component[1], match_glyph, - NULL, + nullptr, &match_length, match_positions, &is_mark_ligature, @@ -792,7 +786,7 @@ struct LigatureSubstFormat1 for (iter.init (this+coverage); iter.more (); iter.next ()) { if (unlikely (iter.get_coverage () >= count)) - break; /* Work around malicious fonts. https://github.com/behdad/harfbuzz/issues/363 */ + break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */ if (c->glyphs->has (iter.get_glyph ())) (this+ligatureSet[iter.get_coverage ()]).closure (c); } @@ -801,13 +795,13 @@ struct LigatureSubstFormat1 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const { TRACE_COLLECT_GLYPHS (this); + if (unlikely (!(this+coverage).add_coverage (c->input))) return; Coverage::Iter iter; unsigned int count = ligatureSet.len; for (iter.init (this+coverage); iter.more (); iter.next ()) { if (unlikely (iter.get_coverage () >= count)) - break; /* Work around malicious fonts. https://github.com/behdad/harfbuzz/issues/363 */ - c->input->add (iter.get_glyph ()); + break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */ (this+ligatureSet[iter.get_coverage ()]).collect_glyphs (c); } } @@ -868,7 +862,7 @@ struct LigatureSubstFormat1 } protected: - USHORT format; /* Format identifier--format = 1 */ + UINT16 format; /* Format identifier--format = 1 */ OffsetTo<Coverage> coverage; /* Offset to Coverage table--from * beginning of Substitution table */ @@ -918,7 +912,7 @@ struct LigatureSubst protected: union { - USHORT format; /* Format identifier */ + UINT16 format; /* Format identifier */ LigatureSubstFormat1 format1; } u; }; @@ -961,7 +955,7 @@ struct ReverseChainSingleSubstFormat1 for (iter.init (this+coverage); iter.more (); iter.next ()) { if (unlikely (iter.get_coverage () >= count)) - break; /* Work around malicious fonts. https://github.com/behdad/harfbuzz/issues/363 */ + break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */ if (c->glyphs->has (iter.get_glyph ())) c->glyphs->add (substitute[iter.get_coverage ()]); } @@ -970,25 +964,22 @@ struct ReverseChainSingleSubstFormat1 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const { TRACE_COLLECT_GLYPHS (this); - - const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack); + if (unlikely (!(this+coverage).add_coverage (c->input))) return; unsigned int count; - (this+coverage).add_coverage (c->input); - count = backtrack.len; for (unsigned int i = 0; i < count; i++) - (this+backtrack[i]).add_coverage (c->before); + if (unlikely (!(this+backtrack[i]).add_coverage (c->before))) return; + const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack); count = lookahead.len; for (unsigned int i = 0; i < count; i++) - (this+lookahead[i]).add_coverage (c->after); + if (unlikely (!(this+lookahead[i]).add_coverage (c->after))) return; const ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead); count = substitute.len; - for (unsigned int i = 0; i < count; i++) - c->output->add (substitute[i]); + c->output->add_array (substitute.array, substitute.len); } inline const Coverage &get_coverage (void) const @@ -1014,14 +1005,17 @@ struct ReverseChainSingleSubstFormat1 const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack); const ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead); + unsigned int start_index = 0, end_index = 0; if (match_backtrack (c, - backtrack.len, (USHORT *) backtrack.array, - match_coverage, this) && + backtrack.len, (UINT16 *) backtrack.array, + match_coverage, this, + &start_index) && match_lookahead (c, - lookahead.len, (USHORT *) lookahead.array, + lookahead.len, (UINT16 *) lookahead.array, match_coverage, this, - 1)) + 1, &end_index)) { + c->buffer->unsafe_to_break_from_outbuffer (start_index, end_index); c->replace_glyph_inplace (substitute[index]); /* Note: We DON'T decrease buffer->idx. The main loop does it * for us. This is useful for preventing surprises if someone @@ -1045,7 +1039,7 @@ struct ReverseChainSingleSubstFormat1 } protected: - USHORT format; /* Format identifier--format = 1 */ + UINT16 format; /* Format identifier--format = 1 */ OffsetTo<Coverage> coverage; /* Offset to Coverage table--from * beginning of table */ @@ -1079,7 +1073,7 @@ struct ReverseChainSingleSubst protected: union { - USHORT format; /* Format identifier */ + UINT16 format; /* Format identifier */ ReverseChainSingleSubstFormat1 format1; } u; }; @@ -1125,7 +1119,7 @@ struct SubstLookupSubTable protected: union { - USHORT sub_format; + UINT16 sub_format; SingleSubst single; MultipleSubst multiple; AlternateSubst alternate; @@ -1277,9 +1271,11 @@ struct SubstLookup : Lookup if (unlikely (get_type () == SubstLookupSubTable::Extension)) { /* The spec says all subtables of an Extension lookup should - * have the same type. This is specially important if one has - * a reverse type! */ + * have the same type, which shall not be the Extension type + * itself. This is specially important if one has a reverse type! */ unsigned int type = get_subtable (0).u.extension.get_type (); + if (unlikely (type == SubstLookupSubTable::Extension)) + return_trace (false); unsigned int count = get_subtable_count (); for (unsigned int i = 1; i < count; i++) if (get_subtable (i).u.extension.get_type () != type) |