diff --git a/fuzzing/fuzz_targets/ojph_compress_fuzz_target.cpp b/fuzzing/fuzz_targets/ojph_compress_fuzz_target.cpp index 8deefc56..0e33c671 100644 --- a/fuzzing/fuzz_targets/ojph_compress_fuzz_target.cpp +++ b/fuzzing/fuzz_targets/ojph_compress_fuzz_target.cpp @@ -35,6 +35,7 @@ //***************************************************************************/ #include +#include #include #include @@ -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; @@ -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 buf(len); + size_t n = fread(buf.data(), 1, len, f); + if(n != static_cast(len)) { + return -1; + } + fclose(f); + LLVMFuzzerTestOneInput(buf.data(), buf.size()); + return 0; +} +#endif \ No newline at end of file diff --git a/fuzzing/seed_corpus/ojph_compress_fuzz_target/w128_h128_b2_79_b3_09.bin b/fuzzing/seed_corpus/ojph_compress_fuzz_target/w128_h128_b2_79_b3_09.bin new file mode 100644 index 00000000..4a4f530f Binary files /dev/null and b/fuzzing/seed_corpus/ojph_compress_fuzz_target/w128_h128_b2_79_b3_09.bin differ