From 375b4687b452181495c243d489bbb75bf19d1825 Mon Sep 17 00:00:00 2001 From: Varun Khaneja Date: Thu, 18 Jan 2018 15:17:44 -0800 Subject: [PATCH] Interpret a blob of memory as a rar file for fuzzing. (#1090) * Interpret a blob of memory as a rar file for fuzzing. (#4) * Use the in-memory representation of the file * Interpret a blob of memory as a rar file for fuzzing. (#5) * Use the in-memory representation of the file * Use a fixed filename, skip calling getpid --- projects/unrar/unrar_fuzzer.cc | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/projects/unrar/unrar_fuzzer.cc b/projects/unrar/unrar_fuzzer.cc index 084aa6a8f0c4..d3b2bc82bee9 100644 --- a/projects/unrar/unrar_fuzzer.cc +++ b/projects/unrar/unrar_fuzzer.cc @@ -1,27 +1,18 @@ -#include #include -#include +#include #include #include "rar.hpp" extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - std::stringstream ss; - ss << "temp-" << getpid() << ".rar"; - static const std::string filename = ss.str(); - std::ofstream file(filename, - std::ios::binary | std::ios::out | std::ios::trunc); - if (!file.is_open()) { - return 0; - } - file.write(reinterpret_cast(data), size); - file.close(); + static const std::string filename = "temp.rar"; std::unique_ptr cmd_data(new CommandData); cmd_data->ParseArg(const_cast(L"-p")); cmd_data->ParseArg(const_cast(L"x")); cmd_data->ParseDone(); std::wstring wide_filename(filename.begin(), filename.end()); + cmd_data->SetArcInMem(const_cast(data), size); cmd_data->AddArcName(wide_filename.c_str()); try { @@ -30,7 +21,5 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { } catch (...) { } - unlink(filename.c_str()); - return 0; }