fuzz_compression.c 788 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <stdint.h>
  2. #include "fuzz_manager.h"
  3. #include "jpegoptim.h"
  4. int LLVMFuzzerTestOneInput(const uint8_t *data, const size_t size)
  5. {
  6. int rc = -1;
  7. struct stat file_stat;
  8. fuzz_manager_init();
  9. if (0 != lstat(fuzz_manager.fuzz_file_name, &file_stat)) {
  10. // Getting file stat failed
  11. goto end;
  12. }
  13. // Write data to fuzz file
  14. FILE *fuzz_file = fopen(fuzz_manager.fuzz_file_name, "wb+");
  15. if (!fuzz_file) {
  16. goto end;
  17. }
  18. if (size != fwrite(data, sizeof(uint8_t), size, fuzz_file)) {
  19. goto end;
  20. }
  21. fclose(fuzz_file);
  22. optimize(
  23. fuzz_manager.log_fh,
  24. fuzz_manager.fuzz_file_name,
  25. fuzz_manager.new_fuzz_file_name,
  26. fuzz_manager.tmp_dir,
  27. &file_stat,
  28. &fuzz_manager.rate,
  29. &fuzz_manager.saved
  30. );
  31. rc = 0;
  32. end:
  33. return rc;
  34. }