From e20e47eaa1b7dd33ac63ab0eaa8f5ea1bf7775c2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 14 Nov 2017 20:25:29 -0800 Subject: [PATCH] [glyf] Try fixing undefined-behavior Might fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=1463 --- src/hb-ot-glyf-table.hh | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index dba102260..1ac12557d 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -54,11 +54,8 @@ struct loca } protected: - union { - USHORT shortsZ[VAR]; /* Location offset divided by 2. */ - ULONG longsZ[VAR]; /* Location offset. */ - } u; - DEFINE_SIZE_ARRAY (0, u.longsZ); + BYTE dataX[VAR]; /* Location data. */ + DEFINE_SIZE_ARRAY (0, dataX); }; @@ -134,13 +131,15 @@ struct glyf unsigned int start_offset, end_offset; if (short_offset) { - start_offset = 2 * loca_table->u.shortsZ[glyph]; - end_offset = 2 * loca_table->u.shortsZ[glyph + 1]; + const USHORT *offsets = (const USHORT *) loca_table->dataX; + start_offset = 2 * offsets[glyph]; + end_offset = 2 * offsets[glyph + 1]; } else { - start_offset = loca_table->u.longsZ[glyph]; - end_offset = loca_table->u.longsZ[glyph + 1]; + const ULONG *offsets = (const ULONG *) loca_table->dataX; + start_offset = offsets[glyph]; + end_offset = offsets[glyph + 1]; } if (start_offset > end_offset || end_offset > glyf_len)