From 62486c6e7c724143b9bc92eda26393249210ff70 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 2 Dec 2022 09:24:51 +0100 Subject: [PATCH 1/4] FIX: Fix possible division by zero - closes https://github.com/assimp/assimp/issues/4819 --- code/AssetLib/MDL/MDLLoader.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/code/AssetLib/MDL/MDLLoader.cpp b/code/AssetLib/MDL/MDLLoader.cpp index f4b4c4d26..b60657805 100644 --- a/code/AssetLib/MDL/MDLLoader.cpp +++ b/code/AssetLib/MDL/MDLLoader.cpp @@ -405,11 +405,13 @@ void MDLImporter::InternReadFile_Quake1() { } // go to the end of the skin section / the beginning of the next skin bool overflow = false; - if ((pcHeader->skinheight > INT_MAX / pcHeader->skinwidth) || (pcHeader->skinwidth > INT_MAX / pcHeader->skinheight)){ - overflow = true; - } - if (!overflow) { - szCurrent += pcHeader->skinheight * pcHeader->skinwidth +sizeof(float) * iNumImages; + if (pcHeader->skinwidth != 0 || pcHeader->skinheight != 0) { + if ((pcHeader->skinheight > INT_MAX / pcHeader->skinwidth) || (pcHeader->skinwidth > INT_MAX / pcHeader->skinheight)){ + overflow = true; + } + if (!overflow) { + szCurrent += pcHeader->skinheight * pcHeader->skinwidth +sizeof(float) * iNumImages; + } } } } else { From f8bb7704ad439e1f070d489d5fd0b2e81785f111 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 2 Dec 2022 09:43:59 +0100 Subject: [PATCH 2/4] Fix: MAke quaternion check in unittest more robust Just add an epsilon test by using the correct comparator from gtest. --- test/unit/AssimpAPITest_aiQuaternion.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/unit/AssimpAPITest_aiQuaternion.cpp b/test/unit/AssimpAPITest_aiQuaternion.cpp index 8f57bc586..7e93033cf 100644 --- a/test/unit/AssimpAPITest_aiQuaternion.cpp +++ b/test/unit/AssimpAPITest_aiQuaternion.cpp @@ -120,7 +120,11 @@ TEST_F(AssimpAPITest_aiQuaternion, aiQuaternionMultiplyTest) { result_c = result_cpp = random_quat(); result_cpp = result_cpp * temp; aiQuaternionMultiply(&result_c, &temp); - EXPECT_EQ(result_cpp, result_c); + + EXPECT_FLOAT_EQ(result_cpp.x, result_c.x); + EXPECT_FLOAT_EQ(result_cpp.y, result_c.y); + EXPECT_FLOAT_EQ(result_cpp.z, result_c.z); + EXPECT_FLOAT_EQ(result_cpp.w, result_c.w); } TEST_F(AssimpAPITest_aiQuaternion, aiQuaternionInterpolateTest) { @@ -131,5 +135,9 @@ TEST_F(AssimpAPITest_aiQuaternion, aiQuaternionInterpolateTest) { const auto q2 = aiQuaternion(aiVector3D(1,2,1).Normalize(), Math::aiPi() / 2.0f); aiQuaternion::Interpolate(result_cpp, q1, q2, INTERPOLATION); aiQuaternionInterpolate(&result_c, &q1, &q2, INTERPOLATION); - EXPECT_EQ(result_cpp, result_c); + + EXPECT_FLOAT_EQ(result_cpp.x, result_c.x); + EXPECT_FLOAT_EQ(result_cpp.y, result_c.y); + EXPECT_FLOAT_EQ(result_cpp.z, result_c.z); + EXPECT_FLOAT_EQ(result_cpp.w, result_c.w); } From 81f85a6f938f8c7bfd6155639589ae2aee0331d1 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 5 Dec 2022 13:07:52 +0100 Subject: [PATCH 3/4] Avoid undefined-shift in Assimp::ASE::Parser::ParseLV4MeshFace. --- code/AssetLib/ASE/ASEParser.cpp | 8 +++++++- code/AssetLib/ASE/ASEParser.h | 9 +++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/code/AssetLib/ASE/ASEParser.cpp b/code/AssetLib/ASE/ASEParser.cpp index 96346bdcb..839d308de 100644 --- a/code/AssetLib/ASE/ASEParser.cpp +++ b/code/AssetLib/ASE/ASEParser.cpp @@ -1774,7 +1774,13 @@ void Parser::ParseLV4MeshFace(ASE::Face &out) { // FIX: There needn't always be a value, sad but true while (true) { if (*filePtr < '9' && *filePtr >= '0') { - out.iSmoothGroup |= (1 << strtoul10(filePtr, &filePtr)); + uint32_t value = strtoul10(filePtr, &filePtr); + if (value < 32) { + out.iSmoothGroup |= (1 << strtoul10(filePtr, &filePtr)); + } else { + const std::string message = std::string("Unable to set smooth group, value with ") + ai_to_string(value) + std::string(" out of range"); + LogWarning(message.c_str()); + } } SkipSpaces(&filePtr); if (',' != *filePtr) { diff --git a/code/AssetLib/ASE/ASEParser.h b/code/AssetLib/ASE/ASEParser.h index 8cda32f24..79cb43f89 100644 --- a/code/AssetLib/ASE/ASEParser.h +++ b/code/AssetLib/ASE/ASEParser.h @@ -4,7 +4,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2022, assimp team - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -385,12 +384,10 @@ struct Dummy : public BaseNode { /** \brief Class to parse ASE files */ class Parser { -private: - Parser() AI_NO_EXCEPT { - // empty - } - public: + /// @brief No default constructor. + Parser() AI_NO_EXCEPT = delete + // ------------------------------------------------------------------- //! Construct a parser from a given input file which is //! guaranteed to be terminated with zero. From 9d57ac9cc5cde97b01b5c0afb7d07835c3af946c Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 5 Dec 2022 13:15:42 +0100 Subject: [PATCH 4/4] Fix:Add missing semicolon. --- code/AssetLib/ASE/ASELoader.cpp | 4 ---- code/AssetLib/ASE/ASELoader.h | 2 +- code/AssetLib/ASE/ASEParser.h | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/code/AssetLib/ASE/ASELoader.cpp b/code/AssetLib/ASE/ASELoader.cpp index abf4fb9cf..951e8539d 100644 --- a/code/AssetLib/ASE/ASELoader.cpp +++ b/code/AssetLib/ASE/ASELoader.cpp @@ -87,10 +87,6 @@ ASEImporter::ASEImporter() : // empty } -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -ASEImporter::~ASEImporter() = default; - // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. bool ASEImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const { diff --git a/code/AssetLib/ASE/ASELoader.h b/code/AssetLib/ASE/ASELoader.h index cd9123556..2509671ef 100644 --- a/code/AssetLib/ASE/ASELoader.h +++ b/code/AssetLib/ASE/ASELoader.h @@ -62,7 +62,7 @@ namespace Assimp { class ASEImporter : public BaseImporter { public: ASEImporter(); - ~ASEImporter() override; + ~ASEImporter() override = default; // ------------------------------------------------------------------- /** Returns whether the class can handle the format of the given file. diff --git a/code/AssetLib/ASE/ASEParser.h b/code/AssetLib/ASE/ASEParser.h index 79cb43f89..c41cd59d3 100644 --- a/code/AssetLib/ASE/ASEParser.h +++ b/code/AssetLib/ASE/ASEParser.h @@ -386,7 +386,7 @@ struct Dummy : public BaseNode { class Parser { public: /// @brief No default constructor. - Parser() AI_NO_EXCEPT = delete + Parser() = delete; // ------------------------------------------------------------------- //! Construct a parser from a given input file which is