run_decode_fuzzer.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* Copyright 2016 Google Inc. All Rights Reserved.
  2. Distributed under MIT license.
  3. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
  4. */
  5. /* Simple runner for decode_fuzzer.cc */
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <stdint.h>
  10. void LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
  11. int main(int argc, char* *argv) {
  12. if (argc != 2) {
  13. fprintf(stderr, "Exactly one argument is expected.\n");
  14. exit(EXIT_FAILURE);
  15. }
  16. FILE* f = fopen(argv[1], "r");
  17. if (!f) {
  18. fprintf(stderr, "Failed to open input file.");
  19. exit(EXIT_FAILURE);
  20. }
  21. size_t max_len = 1 << 20;
  22. unsigned char* tmp = (unsigned char*)malloc(max_len);
  23. size_t len = fread(tmp, 1, max_len, f);
  24. if (ferror(f)) {
  25. fclose(f);
  26. fprintf(stderr, "Failed read input file.");
  27. exit(EXIT_FAILURE);
  28. }
  29. /* Make data after the end "inaccessible". */
  30. unsigned char* data = (unsigned char*)malloc(len);
  31. memcpy(data, tmp, len);
  32. free(tmp);
  33. LLVMFuzzerTestOneInput(data, len);
  34. free(data);
  35. exit(EXIT_SUCCESS);
  36. }