Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpret a blob of memory as a rar file for fuzzing. #1090

Merged
merged 2 commits into from
Jan 18, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions projects/unrar/unrar_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char *>(data), size);
file.close();

std::unique_ptr<CommandData> cmd_data(new CommandData);
cmd_data->ParseArg(const_cast<wchar_t *>(L"-p"));
cmd_data->ParseArg(const_cast<wchar_t *>(L"x"));
cmd_data->ParseDone();
std::wstring wide_filename(filename.begin(), filename.end());
cmd_data->SetArcInMem(const_cast<unsigned char *>(data), size);
cmd_data->AddArcName(wide_filename.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the filename be entirely removed now, or is it still required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it is still required. Once we decide that we are definitely going down this path (in-memory), I can convince the maintainer to support it better i.e. not have to set filename at all,

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does filename have to be unique, otherwise, we can just set it to a default like temp.rar ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't have to be but I agree that having a fixed name now is possible and faster so let me change that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


try {
Expand All @@ -30,7 +24,5 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
} catch (...) {
}

unlink(filename.c_str());

return 0;
}