Fix stack overflow (#5764)

Co-authored-by: Kim Kulling <kimkulling@users.noreply.github.com>
pull/5751/head
dataisland 2024-09-10 16:15:31 -05:00 committed by GitHub
parent 3bd98611d7
commit ab12e8d8ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View File

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

View File

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