File: sndfile_fuzzer.cc

package info (click to toggle)
libsndfile 1.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 5,120 kB
  • sloc: ansic: 55,350; cpp: 1,108; python: 791; makefile: 539; sh: 539; cs: 122
file content (39 lines) | stat: -rw-r--r-- 878 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sndfile.h>
#include <inttypes.h>

#include "sndfile_fuzz_header.h"

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{  VIO_DATA vio_data ;
   SF_VIRTUAL_IO vio ;
   SF_INFO sndfile_info ;
   SNDFILE *sndfile = NULL ;
   float* read_buffer = NULL ;

   int err = sf_init_file(data, size, &sndfile, &vio_data, &vio, &sndfile_info) ;
   if (err)
     goto EXIT_LABEL ;

   // Just the right number of channels. Create some buffer space for reading.
   read_buffer = (float*)malloc(sizeof(float) * sndfile_info.channels);
   if (read_buffer == NULL)
     abort() ;

   while (sf_readf_float(sndfile, read_buffer, 1))
   {
     // Do nothing with the data.
   }

EXIT_LABEL:

   if (sndfile != NULL)
     sf_close(sndfile) ;

   free(read_buffer) ;

   return 0 ;
}