Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 27 additions & 1 deletion fuzzing/fuzz_targets/ojph_compress_fuzz_target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
//***************************************************************************/

#include <cstdint>
#include <vector>
#include <cstdlib>
#include <iostream>

Expand All @@ -57,8 +58,9 @@

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
{
if (Size < 5)
if (Size < 5) {
return 0;
}

ojph::ui32 width = (Data[0] & 0x7F) + 1;
ojph::ui32 height = (Data[1] & 0x7F) + 1;
Expand Down Expand Up @@ -129,3 +131,27 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
}
return 0;
}

#ifdef OJPH_FUZZ_TARGET_MAIN
int main(int argc, char **argv) {
if (argc != 2) {
return -1;
}
FILE *f = fopen(argv[1], "rb");
if (!f) { return -1; }
fseek(f, 0, SEEK_END);
long len = ftell(f);
if (len < 0) {
return -1;
}
rewind(f);
std::vector<uint8_t> buf(len);
size_t n = fread(buf.data(), 1, len, f);
if(n != static_cast<size_t>(len)) {
return -1;
}
fclose(f);
LLVMFuzzerTestOneInput(buf.data(), buf.size());
return 0;
}
#endif
Binary file not shown.
Loading