From 299eca0c3b28c99add006420bc667431d874fb2e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 24 Jan 2019 17:17:00 +0100 Subject: [PATCH] [AAT] Handle out-of-bounds classes --- src/hb-aat-layout-common.hh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/hb-aat-layout-common.hh b/src/hb-aat-layout-common.hh index e3b2a2be1..c6205e752 100644 --- a/src/hb-aat-layout-common.hh +++ b/src/hb-aat-layout-common.hh @@ -511,9 +511,10 @@ struct StateTable const Entry *get_entries () const { return (this+entryTable).arrayZ; } - const Entry *get_entryZ (int state, unsigned int klass) const + const Entry &get_entry (int state, unsigned int klass) const { - if (unlikely (klass >= nClasses)) return nullptr; + if (unlikely (klass >= nClasses)) + klass = StateTable >::CLASS_OUT_OF_BOUNDS; const HBUSHORT *states = (this+stateArrayTable).arrayZ; const Entry *entries = (this+entryTable).arrayZ; @@ -521,7 +522,7 @@ struct StateTable unsigned int entry = states[state * nClasses + klass]; DEBUG_MSG (APPLY, nullptr, "e%u", entry); - return &entries[entry]; + return entries[entry]; } bool sanitize (hb_sanitize_context_t *c, @@ -752,9 +753,7 @@ struct StateTableDriver machine.get_class (buffer->info[buffer->idx].codepoint, num_glyphs) : (unsigned) StateTable::CLASS_END_OF_TEXT; DEBUG_MSG (APPLY, nullptr, "c%u at %u", klass, buffer->idx); - const Entry *entry = machine.get_entryZ (state, klass); - if (unlikely (!entry)) - break; + const Entry *entry = &machine.get_entry (state, klass); /* Unsafe-to-break before this if not in state 0, as things might * go differently if we start from state 0 here. @@ -773,7 +772,7 @@ struct StateTableDriver /* Unsafe-to-break if end-of-text would kick in here. */ if (buffer->idx + 2 <= buffer->len) { - const Entry *end_entry = machine.get_entryZ (state, StateTable::CLASS_END_OF_TEXT); + const Entry *end_entry = &machine.get_entry (state, StateTable::CLASS_END_OF_TEXT); if (c->is_actionable (this, end_entry)) buffer->unsafe_to_break (buffer->idx, buffer->idx + 2); }