From 5e091572d54a509d8a7a0ea22a1aa1141fbf402e Mon Sep 17 00:00:00 2001 From: tyler92 Date: Mon, 30 Dec 2024 12:15:50 +0200 Subject: [PATCH] Fix stack overflow in LWS loader (#5941) Co-authored-by: Kim Kulling --- code/AssetLib/LWS/LWSLoader.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/code/AssetLib/LWS/LWSLoader.cpp b/code/AssetLib/LWS/LWSLoader.cpp index 226615a4a..40a788a10 100644 --- a/code/AssetLib/LWS/LWSLoader.cpp +++ b/code/AssetLib/LWS/LWSLoader.cpp @@ -585,6 +585,15 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy // and add the file to the import list SkipSpaces(&c, end); std::string path = FindLWOFile(c); + + if (path.empty()) { + throw DeadlyImportError("LWS: Invalid LoadObjectLayer: empty path."); + } + + if (path == pFile) { + throw DeadlyImportError("LWS: Invalid LoadObjectLayer: self reference."); + } + d.path = path; d.id = batch.AddLoadRequest(path, 0, &props); @@ -602,6 +611,15 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy d.number = cur_object++; } std::string path = FindLWOFile(c); + + if (path.empty()) { + throw DeadlyImportError("LWS: Invalid LoadObject: empty path."); + } + + if (path == pFile) { + throw DeadlyImportError("LWS: Invalid LoadObject: self reference."); + } + d.id = batch.AddLoadRequest(path, 0, nullptr); d.path = path;