Fix recursion counter check. Add control to override depth of nested … (#4953)

* Fix recursion counter check. Add control to override depth of nested objects.

* Change if-condition to `>=`
This commit is contained in:
Vladimir Glavnyy
2018-10-04 23:27:37 +07:00
committed by Wouter van Oortmerssen
parent c0698cc33f
commit 925c1d77fc
5 changed files with 38 additions and 5 deletions

View File

@@ -115,8 +115,8 @@ CheckedError Parser::Error(const std::string &msg) {
inline CheckedError NoError() { return CheckedError(false); }
CheckedError Parser::RecurseError() {
return Error("maximum parsing recursion of " + NumToString(kMaxParsingDepth) +
" reached");
return Error("maximum parsing recursion of " +
NumToString(FLATBUFFERS_MAX_PARSING_DEPTH) + " reached");
}
inline std::string OutOfRangeErrorMsg(int64_t val, const std::string &op,
@@ -2254,7 +2254,10 @@ bool Parser::ParseFlexBuffer(const char *source, const char *source_filename,
bool Parser::Parse(const char *source, const char **include_paths,
const char *source_filename) {
return !ParseRoot(source, include_paths, source_filename).Check();
FLATBUFFERS_ASSERT(0 == recurse_protection_counter);
auto r = !ParseRoot(source, include_paths, source_filename).Check();
FLATBUFFERS_ASSERT(0 == recurse_protection_counter);
return r;
}
CheckedError Parser::StartParseFile(const char *source,