sndfile_fuzzer.cc 878 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <stdint.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sys/types.h>
  5. #include <sndfile.h>
  6. #include <inttypes.h>
  7. #include "sndfile_fuzz_header.h"
  8. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
  9. { VIO_DATA vio_data ;
  10. SF_VIRTUAL_IO vio ;
  11. SF_INFO sndfile_info ;
  12. SNDFILE *sndfile = NULL ;
  13. float* read_buffer = NULL ;
  14. int err = sf_init_file(data, size, &sndfile, &vio_data, &vio, &sndfile_info) ;
  15. if (err)
  16. goto EXIT_LABEL ;
  17. // Just the right number of channels. Create some buffer space for reading.
  18. read_buffer = (float*)malloc(sizeof(float) * sndfile_info.channels);
  19. if (read_buffer == NULL)
  20. abort() ;
  21. while (sf_readf_float(sndfile, read_buffer, 1))
  22. {
  23. // Do nothing with the data.
  24. }
  25. EXIT_LABEL:
  26. if (sndfile != NULL)
  27. sf_close(sndfile) ;
  28. free(read_buffer) ;
  29. return 0 ;
  30. }