From a570edcde2f89e59b5ccd4867a8c0eed084bf35d Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Fri, 2 Mar 2018 00:06:03 +0330 Subject: [PATCH] [COLR] Sanitize BaseGlyphRecord (#854) --- src/hb-ot-colr-table.hh | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/hb-ot-colr-table.hh b/src/hb-ot-colr-table.hh index c5bc2ccb1..08a39a99a 100644 --- a/src/hb-ot-colr-table.hh +++ b/src/hb-ot-colr-table.hh @@ -42,10 +42,10 @@ struct LayerRecord inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (true); + return_trace (c->check_struct (this)); } - HBUINT16 gID; /* Glyph ID of layer glyph */ + GlyphID gID; /* Glyph ID of layer glyph */ HBUINT16 paletteIndex; /* Index value to use with a selected color palette */ public: DEFINE_SIZE_STATIC (4); @@ -53,13 +53,15 @@ struct LayerRecord struct BaseGlyphRecord { - inline bool sanitize (hb_sanitize_context_t *c, unsigned int palettes) const + inline bool sanitize (hb_sanitize_context_t *c, const void *base) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this)); + return_trace (c->check_struct (this) && + firstLayerIndex.sanitize (c, base) && + c->check_array ((const void*) &firstLayerIndex, sizeof (LayerRecord), numLayers)); } - HBUINT16 gID; /* Glyph ID of reference glyph */ + GlyphID gID; /* Glyph ID of reference glyph */ OffsetTo firstLayerIndex; /* Index to the layer record */ HBUINT16 numLayers; /* Number of color layers associated with this glyph */ @@ -74,9 +76,17 @@ struct COLR inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && - c->check_array ((const void*) &baseGlyphRecords, sizeof (BaseGlyphRecord), numBaseGlyphRecords) && - c->check_array ((const void*) &layerRecordsOffset, sizeof (LayerRecord), numLayerRecords)); + if (!(c->check_struct (this) && + c->check_array ((const void*) &baseGlyphRecords, sizeof (BaseGlyphRecord), numBaseGlyphRecords) && + c->check_array ((const void*) &layerRecordsOffset, sizeof (LayerRecord), numLayerRecords))) + return_trace (false); + + const BaseGlyphRecord *base_glyph_records = &baseGlyphRecords (this); + for (unsigned int i = 0; i < numBaseGlyphRecords; ++i) + if (!(base_glyph_records[i].sanitize (c, this))) + return_trace (false); + + return_trace (true); } protected: @@ -87,7 +97,6 @@ struct COLR LOffsetTo layerRecordsOffset; /* Offset to Layer Records */ HBUINT16 numLayerRecords; /* Number of Layer Records */ - public: DEFINE_SIZE_STATIC (14); };