From 2e767d0cc2b3cef7263f4e001b6be6f8d02e4c4c Mon Sep 17 00:00:00 2001 From: Varun Khaneja Date: Thu, 18 Jan 2018 14:42:12 -0800 Subject: [PATCH 1/2] Interpret a blob of memory as a rar file for fuzzing. (#4) * Use the in-memory representation of the file --- projects/unrar/unrar_fuzzer.cc | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/projects/unrar/unrar_fuzzer.cc b/projects/unrar/unrar_fuzzer.cc index 084aa6a8f0c4..03db54be8978 100644 --- a/projects/unrar/unrar_fuzzer.cc +++ b/projects/unrar/unrar_fuzzer.cc @@ -9,19 +9,13 @@ 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(); 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 +24,5 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { } catch (...) { } - unlink(filename.c_str()); - return 0; } From c67f73127de9349b7dc4069d5e8beb093db07a4c Mon Sep 17 00:00:00 2001 From: Varun Khaneja Date: Thu, 18 Jan 2018 15:11:50 -0800 Subject: [PATCH 2/2] 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 | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/projects/unrar/unrar_fuzzer.cc b/projects/unrar/unrar_fuzzer.cc index 03db54be8978..d3b2bc82bee9 100644 --- a/projects/unrar/unrar_fuzzer.cc +++ b/projects/unrar/unrar_fuzzer.cc @@ -1,14 +1,11 @@ -#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(); + static const std::string filename = "temp.rar"; std::unique_ptr cmd_data(new CommandData); cmd_data->ParseArg(const_cast(L"-p"));