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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#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)
{ // One byte is needed for deciding which function to target.
if (size == 0)
return 0 ;
const uint8_t decider = *data ;
data += 1 ;
size -= 1 ;
SF_INFO sndfile_info ;
VIO_DATA vio_data ;
SF_VIRTUAL_IO vio ;
SNDFILE *sndfile = 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.
switch (decider % 3)
{ case 0 :
{
short* read_buffer = NULL ;
read_buffer = (short*)malloc(sizeof(short) * size);
if (read_buffer == NULL)
abort() ;
while (sf_read_short(sndfile, read_buffer, size))
{
// Do nothing with the data.
}
free(read_buffer) ;
}
break ;
case 1 :
{
int* read_buffer = NULL ;
read_buffer = (int*)malloc(sizeof(int) * size) ;
if (read_buffer == NULL)
abort() ;
while (sf_read_int(sndfile, read_buffer, size))
{
// Do nothing with the data.
}
free(read_buffer) ;
}
break ;
case 2 :
{
double* read_buffer = NULL ;
read_buffer = (double*)malloc(sizeof(double) * size) ;
if (read_buffer == NULL)
abort() ;
while (sf_read_double(sndfile, read_buffer, size))
{
// Do nothing with the data.
}
free(read_buffer) ;
}
break ;
default :
break ;
} ;
EXIT_LABEL:
if (sndfile != NULL)
sf_close(sndfile);
return 0 ;
}
|