summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Glavnyy <31897320+vglavnyy@users.noreply.github.com>2021-01-09 02:09:41 +0700
committerGitHub <noreply@github.com>2021-01-08 11:09:41 -0800
commit85719669cb90e8f6a614ea8dd744efb93855bfa2 (patch)
tree3b40cb0fcd8dab63257339092b82b1717db8a89e
parent809fe49c7a35011547501be83c84b76a464684ac (diff)
downloadflatbuffers-85719669cb90e8f6a614ea8dd744efb93855bfa2.tar.gz
flatbuffers-85719669cb90e8f6a614ea8dd744efb93855bfa2.tar.bz2
flatbuffers-85719669cb90e8f6a614ea8dd744efb93855bfa2.zip
[fuzzer] Debug the monster_tets.bfbs on clusterfuzz server (#6392)
For some reason, this fuzzer failed to load the binary schema file when run on the `/clusterfuzz` server. Issue: https://oss-fuzz.com/testcase-detail/6215075358703616 This issue doesn't reproduce locally with the latest oss-fuzz docker image.
-rw-r--r--tests/fuzzer/flatbuffers_monster_fuzzer.cc38
1 files changed, 28 insertions, 10 deletions
diff --git a/tests/fuzzer/flatbuffers_monster_fuzzer.cc b/tests/fuzzer/flatbuffers_monster_fuzzer.cc
index 2d0bf26c..4a57f766 100644
--- a/tests/fuzzer/flatbuffers_monster_fuzzer.cc
+++ b/tests/fuzzer/flatbuffers_monster_fuzzer.cc
@@ -18,6 +18,7 @@
#include <stdint.h>
#include <clocale>
+#include <filesystem>
#include <string>
#include "cpp17/generated_cpp17/monster_test_generated.h"
@@ -33,22 +34,39 @@ static constexpr uint8_t flags_strict_json = 0x80;
static constexpr uint8_t flags_skip_unexpected_fields_in_json = 0x40;
static constexpr uint8_t flags_allow_non_utf8 = 0x20;
+bool TestFileExists(const char *file_name) {
+ namespace fs = std::filesystem;
+ const bool file_exists = flatbuffers::FileExists(file_name);
+ TEST_OUTPUT_LINE("@DEBUG: test file, exists: %d, name:'%s'", file_exists,
+ file_name);
+ if (file_exists) return true;
+
+ const auto cwd = fs::current_path();
+ TEST_OUTPUT_LINE("@DEBUG: file '%s' not found with flatbuffers::FileExists()",
+ file_name);
+ TEST_OUTPUT_LINE("@DEBUG: CWD: '%s', fs::exists: %d", cwd.c_str(),
+ fs::exists(cwd / file_name));
+ for (const auto &entry : fs::directory_iterator(cwd)) {
+ TEST_OUTPUT_LINE("@DEBUG: CWD entry: '%s'", entry.path().c_str());
+ }
+ return false;
+}
+
std::string LoadBinarySchema(const char *file_name) {
- std::string schemafile;
- TEST_EQ(true,
- flatbuffers::LoadFile(file_name, true, &schemafile));
-
- flatbuffers::Verifier verifier(
- reinterpret_cast<const uint8_t *>(schemafile.c_str()),
- schemafile.size());
- TEST_EQ(true, reflection::VerifySchemaBuffer(verifier));
- return schemafile;
+ TEST_EQ(true, TestFileExists(file_name));
+ std::string schemafile;
+ TEST_EQ(true, flatbuffers::LoadFile(file_name, true, &schemafile));
+
+ flatbuffers::Verifier verifier(
+ reinterpret_cast<const uint8_t *>(schemafile.c_str()), schemafile.size());
+ TEST_EQ(true, reflection::VerifySchemaBuffer(verifier));
+ return schemafile;
}
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");
+ static const std::string schemafile = LoadBinarySchema("monster_test.bfbs");
// parse schema first, so we can use it to parse the data after
flatbuffers::Parser parser;
TEST_EQ(true, parser.Deserialize(