From 55885f7a2442a602fbcc1c4e849db54946b942ff Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Tue, 26 Mar 2024 10:23:14 +0100 Subject: [PATCH] #4329 Don't accept non-finite floats --- src/ifcparse/IfcWrite.cpp | 26 +++++++++++++++++++++++++- src/ifcparse/IfcWrite.h | 7 ++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/ifcparse/IfcWrite.cpp b/src/ifcparse/IfcWrite.cpp index a82a31d15f..3d125fb06c 100644 --- a/src/ifcparse/IfcWrite.cpp +++ b/src/ifcparse/IfcWrite.cpp @@ -295,4 +295,28 @@ void IfcWriteArgument::set(IfcUtil::IfcBaseInterface*const& v) { } else { container = boost::blank(); } -} \ No newline at end of file +} + +// 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 c69ca6052b..a79998a8ff 100644 --- a/src/ifcparse/IfcWrite.h +++ b/src/ifcparse/IfcWrite.h @@ -142,7 +142,12 @@ namespace IfcWrite { // 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;