|
@@ -271,10 +271,16 @@ void MDLImporter::InternReadFile(const std::string &pFile,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// ------------------------------------------------------------------------------------------------
|
|
|
+// Check whether we're still inside the valid file range
|
|
|
+bool MDLImporter::IsPosValid(const void *szPos) const {
|
|
|
+ return szPos && (const unsigned char *)szPos <= this->mBuffer + this->iFileSize && szPos >= this->mBuffer;
|
|
|
+}
|
|
|
+
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
// 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 || szPos < this->mBuffer) {
|
|
|
+ if (!IsPosValid(szPos)) {
|
|
|
throw DeadlyImportError("Invalid MDL file. The file is too small "
|
|
|
"or contains invalid data.");
|
|
|
}
|
|
@@ -284,7 +290,7 @@ void MDLImporter::SizeCheck(const void *szPos) {
|
|
|
// Just for debugging purposes
|
|
|
void MDLImporter::SizeCheck(const void *szPos, const char *szFile, unsigned int iLine) {
|
|
|
ai_assert(nullptr != szFile);
|
|
|
- if (!szPos || (const unsigned char *)szPos > mBuffer + iFileSize) {
|
|
|
+ if (!IsPosValid(szPos)) {
|
|
|
// remove a directory if there is one
|
|
|
const char *szFilePtr = ::strrchr(szFile, '\\');
|
|
|
if (!szFilePtr) {
|