mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-10 23:17:27 +00:00
[idl_parser] Improve stack overflow protection (#6364)
* [idl_parser] Improve stack overflow protection Add stack overflow protection for Flexbuffer and nested Flatbuffer parsers. Replaces the `Recurse()` method by the new ParseDepthGuard RAII class. * Remove move operator from Parser. It was wrong decision to add move ctor and assignment into Parser class. These operators will make it extremely difficult to add constant or reference fields in the future. * Remove ';' from definition of FLATBUFFERS_DELETE_FUNC * Format code * Make this PR compatible with MSVC2010 (it doesn't support inherited ctor)
This commit is contained in:
@@ -10,7 +10,7 @@ option(BUILD_DEBUGGER "Compile a debugger with main() and without libFuzzer" OFF
|
||||
|
||||
if(NOT DEFINED FLATBUFFERS_MAX_PARSING_DEPTH)
|
||||
# Force checking of RecursionError in the test
|
||||
set(FLATBUFFERS_MAX_PARSING_DEPTH 8)
|
||||
set(FLATBUFFERS_MAX_PARSING_DEPTH 24)
|
||||
endif()
|
||||
message(STATUS "FLATBUFFERS_MAX_PARSING_DEPTH: ${FLATBUFFERS_MAX_PARSING_DEPTH}")
|
||||
|
||||
|
||||
@@ -45,7 +45,8 @@ std::string LoadBinarySchema(const char *file_name) {
|
||||
return schemafile;
|
||||
}
|
||||
|
||||
flatbuffers::Parser make_parser(const flatbuffers::IDLOptions opts) {
|
||||
std::string do_test(const flatbuffers::IDLOptions &opts,
|
||||
const std::string input_json) {
|
||||
// once loaded from disk
|
||||
static const std::string schemafile = LoadBinarySchema("./monster_test.bfbs");
|
||||
// parse schema first, so we can use it to parse the data after
|
||||
@@ -55,12 +56,7 @@ flatbuffers::Parser make_parser(const flatbuffers::IDLOptions opts) {
|
||||
schemafile.size()));
|
||||
// (re)define parser options
|
||||
parser.opts = opts;
|
||||
return parser;
|
||||
}
|
||||
|
||||
std::string do_test(const flatbuffers::IDLOptions &opts,
|
||||
const std::string input_json) {
|
||||
auto parser = make_parser(opts);
|
||||
std::string jsongen;
|
||||
if (parser.ParseJson(input_json.c_str())) {
|
||||
flatbuffers::Verifier verifier(parser.builder_.GetBufferPointer(),
|
||||
|
||||
Reference in New Issue
Block a user