Merge pull request #4820 from assimp/kimkulling/MDL_fix_division_by_zero_issue-4819

FIX: Fix possible division by zero
pull/4829/head
Kim Kulling 2022-12-02 10:00:12 +01:00 committed by GitHub
commit 28c155bfb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -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 {

View File

@ -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<float>() / 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);
}