From 163fbf0be11c8448f40c054ea5c69c1a7c6155f3 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Fri, 5 Aug 2022 23:37:11 +0000 Subject: [PATCH] [repacker] Check for nullptr's before sanitizing. --- src/graph/coverage-graph.hh | 2 +- src/graph/gsubgpos-graph.hh | 11 +++++------ src/graph/pairpos-graph.hh | 14 +++++++++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/graph/coverage-graph.hh b/src/graph/coverage-graph.hh index 7309029c2..da71ea6fb 100644 --- a/src/graph/coverage-graph.hh +++ b/src/graph/coverage-graph.hh @@ -66,7 +66,7 @@ struct Coverage : public OT::Layout::Common::Coverage unsigned coverage_size = c.graph.vertices_[coverage_id].table_size (); auto& coverage_v = c.graph.vertices_[coverage_id]; Coverage* coverage_table = (Coverage*) coverage_v.obj.head; - if (!coverage_table->sanitize (coverage_v)) + if (!coverage_table || !coverage_table->sanitize (coverage_v)) return nullptr; auto new_coverage = diff --git a/src/graph/gsubgpos-graph.hh b/src/graph/gsubgpos-graph.hh index 98302ff75..f963a49ad 100644 --- a/src/graph/gsubgpos-graph.hh +++ b/src/graph/gsubgpos-graph.hh @@ -133,7 +133,7 @@ struct Lookup : public OT::Lookup ExtensionFormat1* extension = (ExtensionFormat1*) c.graph.object (ext_subtable_index).head; - if (!extension->sanitize (c.graph.vertices_[ext_subtable_index])) + if (!extension || !extension->sanitize (c.graph.vertices_[ext_subtable_index])) continue; subtable_index = extension->get_subtable_index (c.graph, ext_subtable_index); @@ -143,7 +143,7 @@ struct Lookup : public OT::Lookup } PairPos* pairPos = (PairPos*) c.graph.object (subtable_index).head; - if (!pairPos->sanitize (c.graph.vertices_[subtable_index])) continue; + if (!pairPos || !pairPos->sanitize (c.graph.vertices_[subtable_index])) continue; hb_vector_t new_sub_tables = pairPos->split_subtables (c, subtable_index); if (new_sub_tables.in_error ()) return false; @@ -320,7 +320,7 @@ struct GSTAR : public OT::GSUBGPOS const auto& r = graph.root (); GSTAR* gstar = (GSTAR*) r.obj.head; - if (!gstar->sanitize (r)) + if (!gstar || !gstar->sanitize (r)) return nullptr; return gstar; @@ -366,17 +366,16 @@ struct GSTAR : public OT::GSUBGPOS hb_hashmap_t& lookups /* OUT */) { unsigned lookup_list_idx = get_lookup_list_index (graph); - const LookupList* lookupList = (const LookupList*) graph.object (lookup_list_idx).head; - if (!lookupList->sanitize (graph.vertices_[lookup_list_idx])) + if (!lookupList || !lookupList->sanitize (graph.vertices_[lookup_list_idx])) return; for (unsigned i = 0; i < lookupList->len; i++) { unsigned lookup_idx = graph.index_for_offset (lookup_list_idx, &(lookupList->arrayZ[i])); Lookup* lookup = (Lookup*) graph.object (lookup_idx).head; - if (!lookup->sanitize (graph.vertices_[lookup_idx])) continue; + if (!lookup || !lookup->sanitize (graph.vertices_[lookup_idx])) continue; lookups.set (lookup_idx, lookup); } } diff --git a/src/graph/pairpos-graph.hh b/src/graph/pairpos-graph.hh index d9edfbb55..29dee54d4 100644 --- a/src/graph/pairpos-graph.hh +++ b/src/graph/pairpos-graph.hh @@ -130,7 +130,7 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3sanitize (coverage_v)) + if (!coverage_table || !coverage_table->sanitize (coverage_v)) return false; auto new_coverage = @@ -377,7 +377,9 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4sanitize (coverage_v) + if (!coverage_table + || !coverage_table->sanitize (coverage_v) + || !class_def_1_table || !class_def_1_table->sanitize (class_def_1_v)) return -1; @@ -513,7 +515,9 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4sanitize (coverage_v) + if (!coverage_table + || !coverage_table->sanitize (coverage_v) + || !class_def_1_table || !class_def_1_table->sanitize (class_def_1_v)) return false; @@ -560,7 +564,7 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4sanitize (coverage_v)) + if (!coverage_table || !coverage_table->sanitize (coverage_v)) return &Null(Coverage); return coverage_table; } @@ -572,7 +576,7 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4sanitize (class_def_1_v)) + if (!class_def_1_table || !class_def_1_table->sanitize (class_def_1_v)) return &Null(ClassDef); return class_def_1_table; }