From a764387b90fbe29197453c760c8f90a97c374632 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Tue, 26 Mar 2024 10:23:14 +0100 Subject: [PATCH] Don't accept non-finite floats #4329 --- src/ifcparse/IfcWrite.cpp | 32 ++++++++++++++++++++++++++++++++ src/ifcparse/IfcWrite.h | 11 +++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/ifcparse/IfcWrite.cpp b/src/ifcparse/IfcWrite.cpp index 00b5daf654..bd4e2e99d4 100644 --- a/src/ifcparse/IfcWrite.cpp +++ b/src/ifcparse/IfcWrite.cpp @@ -315,3 +315,35 @@ void IfcWriteArgument::set(IfcUtil::IfcBaseInterface* const& value) { container_ = boost::blank(); } } + +void IfcWriteArgument::set(IfcUtil::IfcBaseInterface*const& v) { + if (v) { + container = v->as(); + } else { + container = boost::blank(); + } +} + +// Overloads to raise exceptions on non-finite values +void IfcWriteArgument::set(const double& v) { + if (!std::isfinite(v)) { + throw IfcParse::IfcException("Only finite values are allowed"); + } + container = v; +} + +void IfcWriteArgument::set(const std::vector& v) { + if (std::any_of(v.begin(), v.end(), [](double v) {return !std::isfinite(v); })) { + throw IfcParse::IfcException("Only finite values are allowed"); + } + container = v; +} + +void IfcWriteArgument::set(const std::vector< std::vector >& v) { + if (std::any_of(v.begin(), v.end(), [](const std::vector& vs) { + return std::any_of(vs.begin(), vs.end(), [](double v) {return !std::isfinite(v); }); + })) { + throw IfcParse::IfcException("Only finite values are allowed"); + } + container = v; +} diff --git a/src/ifcparse/IfcWrite.h b/src/ifcparse/IfcWrite.h index 4895304c1e..a42555dd1c 100644 --- a/src/ifcparse/IfcWrite.h +++ b/src/ifcparse/IfcWrite.h @@ -137,6 +137,17 @@ class IFC_PARSE_API IfcWriteArgument : public Argument { // Overload to detect null values void set(const aggregate_of_aggregate_of_instance::ptr& value); + // Overload to detect null values + void set(IfcUtil::IfcBaseInterface*const & v); + + // Overloads to raise exceptions on non-finite values + void set(const double& v); + void set(const std::vector& v); + void set(const std::vector< std::vector >& v); + + operator int() const; + operator bool() const; + operator boost::logic::tribool() const; // Overload to detect null values void set(IfcUtil::IfcBaseInterface* const& value);