diff options
Diffstat (limited to 'modules/fbx/fbx_parser/FBXParser.cpp')
-rw-r--r-- | modules/fbx/fbx_parser/FBXParser.cpp | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/modules/fbx/fbx_parser/FBXParser.cpp b/modules/fbx/fbx_parser/FBXParser.cpp index 166d98bb8c..2a76c3f67c 100644 --- a/modules/fbx/fbx_parser/FBXParser.cpp +++ b/modules/fbx/fbx_parser/FBXParser.cpp @@ -74,8 +74,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * @brief Implementation of the FBX parser and the rudimentary DOM that we use */ -#include "thirdparty/zlib/zlib.h" #include <stdlib.h> /* strtol */ +#include <zlib.h> #include "ByteSwapper.h" #include "FBXParseTools.h" @@ -131,6 +131,8 @@ Element::Element(const TokenPtr key_token, Parser &parser) : if (!n) { print_error("unexpected end of file, expected bracket, comma or key" + String(parser.LastToken()->StringContents().c_str())); + parser.corrupt = true; + return; } const TokenType ty = n->Type(); @@ -143,6 +145,8 @@ Element::Element(const TokenPtr key_token, Parser &parser) : if (ty != TokenType_OPEN_BRACKET && ty != TokenType_CLOSE_BRACKET && ty != TokenType_COMMA && ty != TokenType_KEY) { print_error("unexpected token; expected bracket, comma or key" + String(n->StringContents().c_str())); + parser.corrupt = true; + return; } } @@ -150,11 +154,17 @@ Element::Element(const TokenPtr key_token, Parser &parser) : compound = new_Scope(parser); parser.scopes.push_back(compound); + if (parser.corrupt) { + return; + } + // current token should be a TOK_CLOSE_BRACKET n = parser.CurrentToken(); if (n && n->Type() != TokenType_CLOSE_BRACKET) { print_error("expected closing bracket" + String(n->StringContents().c_str())); + parser.corrupt = true; + return; } parser.AdvanceToNextToken(); @@ -173,22 +183,31 @@ Scope::Scope(Parser &parser, bool topLevel) { TokenPtr t = parser.CurrentToken(); if (t->Type() != TokenType_OPEN_BRACKET) { print_error("expected open bracket" + String(t->StringContents().c_str())); + parser.corrupt = true; + return; } } TokenPtr n = parser.AdvanceToNextToken(); if (n == nullptr) { print_error("unexpected end of file"); + parser.corrupt = true; + return; } // note: empty scopes are allowed while (n && n->Type() != TokenType_CLOSE_BRACKET) { if (n->Type() != TokenType_KEY) { print_error("unexpected token, expected TOK_KEY" + String(n->StringContents().c_str())); + parser.corrupt = true; + return; } const std::string str = n->StringContents(); + if (parser.corrupt) { + return; + } // std::multimap<std::string, ElementPtr> (key and value) elements.insert(ElementMap::value_type(str, new_Element(n, parser))); @@ -216,7 +235,7 @@ Scope::~Scope() { // ------------------------------------------------------------------------------------------------ Parser::Parser(const TokenList &tokens, bool is_binary) : - tokens(tokens), cursor(tokens.begin()), is_binary(is_binary) { + corrupt(false), tokens(tokens), cursor(tokens.begin()), is_binary(is_binary) { root = new_Scope(*this, true); scopes.push_back(root); } @@ -1231,6 +1250,21 @@ ScopePtr GetRequiredScope(const ElementPtr el) { } // ------------------------------------------------------------------------------------------------ +// extract optional compound scope +ScopePtr GetOptionalScope(const ElementPtr el) { + if (el) { + ScopePtr s = el->Compound(); + TokenPtr token = el->KeyToken(); + + if (token && s) { + return s; + } + } + + return nullptr; +} + +// ------------------------------------------------------------------------------------------------ // get token at a particular index TokenPtr GetRequiredToken(const ElementPtr el, unsigned int index) { if (el) { |