Fix stack overflow (#5764)
Co-authored-by: Kim Kulling <kimkulling@users.noreply.github.com>
This commit is contained in:
@@ -78,7 +78,15 @@ static constexpr aiImporterDesc desc = {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Recursive parsing of LWS files
|
||||
void LWS::Element::Parse(const char *&buffer, const char *end) {
|
||||
namespace {
|
||||
constexpr int MAX_DEPTH = 1000; // Define the maximum depth allowed
|
||||
}
|
||||
|
||||
void LWS::Element::Parse(const char *&buffer, const char *end, int depth) {
|
||||
if (depth > MAX_DEPTH) {
|
||||
throw std::runtime_error("Maximum recursion depth exceeded in LWS::Element::Parse");
|
||||
}
|
||||
|
||||
for (; SkipSpacesAndLineEnd(&buffer, end); SkipLine(&buffer, end)) {
|
||||
|
||||
// begin of a new element with children
|
||||
@@ -121,7 +129,7 @@ void LWS::Element::Parse(const char *&buffer, const char *end) {
|
||||
|
||||
// parse more elements recursively
|
||||
if (sub) {
|
||||
children.back().Parse(buffer, end);
|
||||
children.back().Parse(buffer, end, depth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public:
|
||||
std::list<Element> children;
|
||||
|
||||
//! Recursive parsing function
|
||||
void Parse(const char *&buffer, const char *end);
|
||||
void Parse(const char *&buffer, const char *end, int depth = 0);
|
||||
};
|
||||
|
||||
#define AI_LWS_MASK (0xffffffff >> 4u)
|
||||
|
||||
Reference in New Issue
Block a user