From 23f9990b220a262f14d4c192e737a91294fcebf8 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 4 Jun 2023 07:50:00 +0000 Subject: [PATCH] Fix UNKNOWN READ in aiTexture::~aiTexture --- code/AssetLib/MDL/MDLLoader.cpp | 2 +- code/AssetLib/MDL/MDLMaterialLoader.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/code/AssetLib/MDL/MDLLoader.cpp b/code/AssetLib/MDL/MDLLoader.cpp index 76b61cda5..098b53e76 100644 --- a/code/AssetLib/MDL/MDLLoader.cpp +++ b/code/AssetLib/MDL/MDLLoader.cpp @@ -274,7 +274,7 @@ void MDLImporter::InternReadFile(const std::string &pFile, // ------------------------------------------------------------------------------------------------ // Check whether we're still inside the valid file range void MDLImporter::SizeCheck(const void *szPos) { - if (!szPos || (const unsigned char *)szPos > this->mBuffer + this->iFileSize) { + if (!szPos || (const unsigned char *)szPos > this->mBuffer + this->iFileSize || szPos < this->mBuffer) { throw DeadlyImportError("Invalid MDL file. The file is too small " "or contains invalid data."); } diff --git a/code/AssetLib/MDL/MDLMaterialLoader.cpp b/code/AssetLib/MDL/MDLMaterialLoader.cpp index 799368264..fbda40151 100644 --- a/code/AssetLib/MDL/MDLMaterialLoader.cpp +++ b/code/AssetLib/MDL/MDLMaterialLoader.cpp @@ -703,7 +703,14 @@ void MDLImporter::SkipSkinLump_3DGS_MDL7( tex.pcData = bad_texel; tex.mHeight = iHeight; tex.mWidth = iWidth; - ParseTextureColorData(szCurrent, iMasked, &iSkip, &tex); + + try { + ParseTextureColorData(szCurrent, iMasked, &iSkip, &tex); + } catch (...) { + // FIX: Important, otherwise the destructor will crash + tex.pcData = nullptr; + throw; + } // FIX: Important, otherwise the destructor will crash tex.pcData = nullptr;