From ca5249a179e4669b9a7ef376a2b1de1010b3fb9d Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Mon, 3 Oct 2022 14:05:08 +0200 Subject: [PATCH] More resiliance against wrong attribute counts --- src/ifcparse/IfcParse.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index 888cd60b04..b706c550f5 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -744,16 +744,24 @@ size_t IfcParse::IfcFile::load(unsigned entity_instance_name, const IfcParse::en } if (vector) { - attributes = new Argument*[vector->size()]; - return_value = vector->size(); + // @todo figure out whether all this logic is still necessary, since we know the + // expected amount of attributes and shouldn't be able to access more than allowed + // by the schema. + attributes = new Argument*[(std::max)(num_attributes, vector->size())]{ nullptr }; + + // @todo this appears unnecessary, we increment this in the loop already, + // which is more accurate as the filler can't go above it's size in case + // it uses the pre-allocated c-array. + // -> return_value = vector->size(); + for (size_t i = 0; i < vector->size(); ++i) { attributes[i] = vector->at(i); } - } if (vector != &internal_attribute_vector_) { delete vector; } + } return return_value; }