Skip to content

Commit 375b468

Browse files
aawctmatth
authored andcommitted
Interpret a blob of memory as a rar file for fuzzing. (google#1090)
* Interpret a blob of memory as a rar file for fuzzing. (google#4) * Use the in-memory representation of the file * Interpret a blob of memory as a rar file for fuzzing. (google#5) * Use the in-memory representation of the file * Use a fixed filename, skip calling getpid
1 parent 82bdfd0 commit 375b468

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

projects/unrar/unrar_fuzzer.cc

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
1-
#include <fstream>
21
#include <memory>
3-
#include <sstream>
2+
#include <string>
43
#include <unistd.h>
54

65
#include "rar.hpp"
76

87
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
9-
std::stringstream ss;
10-
ss << "temp-" << getpid() << ".rar";
11-
static const std::string filename = ss.str();
12-
std::ofstream file(filename,
13-
std::ios::binary | std::ios::out | std::ios::trunc);
14-
if (!file.is_open()) {
15-
return 0;
16-
}
17-
file.write(reinterpret_cast<const char *>(data), size);
18-
file.close();
8+
static const std::string filename = "temp.rar";
199

2010
std::unique_ptr<CommandData> cmd_data(new CommandData);
2111
cmd_data->ParseArg(const_cast<wchar_t *>(L"-p"));
2212
cmd_data->ParseArg(const_cast<wchar_t *>(L"x"));
2313
cmd_data->ParseDone();
2414
std::wstring wide_filename(filename.begin(), filename.end());
15+
cmd_data->SetArcInMem(const_cast<unsigned char *>(data), size);
2516
cmd_data->AddArcName(wide_filename.c_str());
2617

2718
try {
@@ -30,7 +21,5 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
3021
} catch (...) {
3122
}
3223

33-
unlink(filename.c_str());
34-
3524
return 0;
3625
}

0 commit comments

Comments
 (0)