From 27c4037e5988d41b92c7c3904d4ceeea8c31586c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 22 Nov 2022 13:12:22 -0700 Subject: [PATCH] [gvar] Micro-optimize boundary-checking --- src/hb-ot-var-gvar-table.hh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index 982c5c4a9..7d83d06a0 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -339,14 +339,17 @@ struct GlyphVariationData if (unlikely (p + 1 > end)) return false; unsigned control = *p++; unsigned run_count = (control & DELTA_RUN_COUNT_MASK) + 1; + if (unlikely (i + run_count > count)) return false; unsigned j; if (control & DELTAS_ARE_ZERO) - for (j = 0; j < run_count && i < count; j++, i++) + { + for (j = 0; j < run_count; j++, i++) deltas.arrayZ[i] = 0; + } else if (control & DELTAS_ARE_WORDS) { if (unlikely (p + run_count * HBUINT16::static_size > end)) return false; - for (j = 0; j < run_count && i < count; j++, i++) + for (j = 0; j < run_count; j++, i++) { deltas.arrayZ[i] = * (const HBINT16 *) p; p += HBUINT16::static_size; @@ -355,13 +358,11 @@ struct GlyphVariationData else { if (unlikely (p + run_count > end)) return false; - for (j = 0; j < run_count && i < count; j++, i++) + for (j = 0; j < run_count; j++, i++) { deltas.arrayZ[i] = * (const HBINT8 *) p++; } } - if (unlikely (j < run_count)) - return false; } return true; }