mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-16 00:54:54 +00:00
Initial commit
added libraries: opus flac libsndfile updated: libvorbis libogg openal - Everything works as expected for now. Bare in mind libsndfile needed the check for whether or not it could find the xiph libraries removed in order for this to work.
This commit is contained in:
parent
05a083ca6f
commit
a745fc3757
1954 changed files with 431332 additions and 21037 deletions
30
Engine/lib/libsndfile/ossfuzz/ci_oss.sh
Normal file
30
Engine/lib/libsndfile/ossfuzz/ci_oss.sh
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
PROJECT_NAME=libsndfile
|
||||
|
||||
# Clone the oss-fuzz repository
|
||||
git clone https://github.com/google/oss-fuzz.git /tmp/ossfuzz
|
||||
|
||||
if [[ ! -d /tmp/ossfuzz/projects/${PROJECT_NAME} ]]
|
||||
then
|
||||
echo "Could not find the ${PROJECT_NAME} project in ossfuzz"
|
||||
|
||||
# Exit with a success code while the libsndfile project is not expected to exist
|
||||
# on oss-fuzz.
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Work out which branch to clone from, inside Docker
|
||||
BRANCH=${GITHUB_REF}
|
||||
|
||||
# Modify the oss-fuzz Dockerfile so that we're checking out the current reference on CI.
|
||||
sed -i "s@RUN.*@RUN git config --global remote.origin.fetch '+refs/pull/*:refs/remotes/origin/pull/*' \&\& git clone https://github.com/libsndfile/libsndfile.git /src/libsndfile \&\& cd /src/libsndfile \&\& git checkout -b ${BRANCH}@" /tmp/ossfuzz/projects/${PROJECT_NAME}/Dockerfile
|
||||
|
||||
# Try and build the fuzzers
|
||||
pushd /tmp/ossfuzz
|
||||
python3 infra/helper.py build_image --pull ${PROJECT_NAME}
|
||||
python3 infra/helper.py build_fuzzers ${PROJECT_NAME}
|
||||
python3 infra/helper.py check_build ${PROJECT_NAME} --engine libfuzzer --sanitizer address --architecture x86_64
|
||||
popd
|
||||
32
Engine/lib/libsndfile/ossfuzz/ossfuzz.sh
Normal file
32
Engine/lib/libsndfile/ossfuzz/ossfuzz.sh
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#!/bin/bash -eu
|
||||
|
||||
# This script is called by the oss-fuzz main project when compiling the fuzz
|
||||
# targets. This script is regression tested by ci_oss.sh.
|
||||
|
||||
# Save off the current folder as the build root.
|
||||
export BUILD_ROOT=$PWD
|
||||
|
||||
echo "CC: ${CC:-}"
|
||||
echo "CXX: ${CXX:-}"
|
||||
echo "LIB_FUZZING_ENGINE: ${LIB_FUZZING_ENGINE:-}"
|
||||
echo "CFLAGS: ${CFLAGS:-}"
|
||||
echo "CXXFLAGS: ${CXXFLAGS:-}"
|
||||
echo "OUT: ${OUT:-}"
|
||||
|
||||
export MAKEFLAGS+="-j$(nproc)"
|
||||
|
||||
# Install dependencies
|
||||
apt-get -y install autoconf autogen automake libtool pkg-config python
|
||||
|
||||
# For now, do not install the following libraries (as they won't be in the
|
||||
# final image):
|
||||
# libasound2-dev libflac-dev libogg-dev libopus-dev libvorbis-dev
|
||||
|
||||
# Compile the fuzzer.
|
||||
autoreconf -vif
|
||||
./configure --disable-shared --enable-ossfuzzers
|
||||
make V=1
|
||||
|
||||
# Copy the fuzzer to the output directory.
|
||||
cp -v ossfuzz/sndfile_fuzzer $OUT/
|
||||
cp -v ossfuzz/sndfile_alt_fuzzer $OUT/
|
||||
79
Engine/lib/libsndfile/ossfuzz/sndfile_alt_fuzzer.cc
Normal file
79
Engine/lib/libsndfile/ossfuzz/sndfile_alt_fuzzer.cc
Normal file
|
|
@ -0,0 +1,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 ;
|
||||
}
|
||||
119
Engine/lib/libsndfile/ossfuzz/sndfile_fuzz_header.h
Normal file
119
Engine/lib/libsndfile/ossfuzz/sndfile_fuzz_header.h
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
#ifndef SNDFILE_FUZZ_HEADER_H
|
||||
#define SNDFILE_FUZZ_HEADER_H
|
||||
|
||||
typedef struct
|
||||
{
|
||||
sf_count_t offset ;
|
||||
sf_count_t length ;
|
||||
const unsigned char *data ;
|
||||
} VIO_DATA ;
|
||||
|
||||
static sf_count_t vfget_filelen (void *user_data)
|
||||
{ VIO_DATA *vf = (VIO_DATA *)user_data ;
|
||||
return vf->length ;
|
||||
}
|
||||
|
||||
static sf_count_t vfseek (sf_count_t offset, int whence, void *user_data)
|
||||
{
|
||||
VIO_DATA *vf = (VIO_DATA *)user_data ;
|
||||
sf_count_t new_offset ;
|
||||
|
||||
switch (whence)
|
||||
{ case SEEK_SET :
|
||||
new_offset = offset ;
|
||||
break ;
|
||||
|
||||
case SEEK_CUR :
|
||||
new_offset = vf->offset + offset ;
|
||||
break ;
|
||||
|
||||
case SEEK_END :
|
||||
new_offset = vf->length + offset ;
|
||||
break ;
|
||||
|
||||
default :
|
||||
break ;
|
||||
}
|
||||
|
||||
/* Ensure you can't seek outside the data */
|
||||
if (new_offset > vf->length)
|
||||
{ /* Trying to seek past the end of the data */
|
||||
printf("vf overseek: new_offset(%" PRId64 ") > vf->length(%" PRId64 ");"
|
||||
" whence(%d), vf->offset(%" PRId64 "), offset(%" PRId64 ")\n",
|
||||
new_offset, vf->length, whence, vf->offset, offset) ;
|
||||
new_offset = vf->length ;
|
||||
}
|
||||
else if (new_offset < 0)
|
||||
{ /* Trying to seek before the start of the data */
|
||||
printf("vf underseek: new_offset(%" PRId64 ") < 0; whence(%d), vf->offset"
|
||||
"(%" PRId64 "), vf->length(%" PRId64 "), offset(%" PRId64 ")\n",
|
||||
new_offset, whence, vf->offset, vf->length, offset) ;
|
||||
new_offset = 0 ;
|
||||
}
|
||||
vf->offset = new_offset ;
|
||||
|
||||
return vf->offset ;
|
||||
}
|
||||
|
||||
static sf_count_t vfread (void *ptr, sf_count_t count, void *user_data)
|
||||
{ VIO_DATA *vf = (VIO_DATA *)user_data ;
|
||||
|
||||
if (vf->offset + count > vf->length)
|
||||
count = vf->length - vf->offset ;
|
||||
|
||||
memcpy(ptr, vf->data + vf->offset, count) ;
|
||||
vf->offset += count ;
|
||||
|
||||
return count ;
|
||||
}
|
||||
|
||||
static sf_count_t vfwrite (const void *ptr, sf_count_t count, void *user_data)
|
||||
{
|
||||
(void)ptr ;
|
||||
(void)count ;
|
||||
(void)user_data ;
|
||||
|
||||
// Cannot write to this virtual file.
|
||||
return 0;
|
||||
}
|
||||
|
||||
static sf_count_t vftell (void *user_data)
|
||||
{ VIO_DATA *vf = (VIO_DATA *)user_data ;
|
||||
|
||||
return vf->offset ;
|
||||
}
|
||||
|
||||
int sf_init_file(const uint8_t *data,
|
||||
size_t size,
|
||||
SNDFILE **sndfile,
|
||||
VIO_DATA *vio_data,
|
||||
SF_VIRTUAL_IO *vio, SF_INFO *sndfile_info)
|
||||
{ float* read_buffer = NULL ;
|
||||
|
||||
// Initialize the virtual IO structure.
|
||||
vio->get_filelen = vfget_filelen ;
|
||||
vio->seek = vfseek ;
|
||||
vio->read = vfread ;
|
||||
vio->write = vfwrite ;
|
||||
vio->tell = vftell ;
|
||||
|
||||
// Initialize the VIO user data.
|
||||
vio_data->data = data ;
|
||||
vio_data->length = size ;
|
||||
vio_data->offset = 0 ;
|
||||
|
||||
memset(sndfile_info, 0, sizeof(SF_INFO)) ;
|
||||
|
||||
// Try and open the virtual file.
|
||||
*sndfile = sf_open_virtual(vio, SFM_READ, sndfile_info, vio_data) ;
|
||||
|
||||
if (sndfile_info->channels == 0)
|
||||
return -1 ;
|
||||
|
||||
if (sndfile_info->channels > 1024 * 1024)
|
||||
return -1 ;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
39
Engine/lib/libsndfile/ossfuzz/sndfile_fuzzer.cc
Normal file
39
Engine/lib/libsndfile/ossfuzz/sndfile_fuzzer.cc
Normal file
|
|
@ -0,0 +1,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 ;
|
||||
}
|
||||
86
Engine/lib/libsndfile/ossfuzz/standaloneengine.cc
Normal file
86
Engine/lib/libsndfile/ossfuzz/standaloneengine.cc
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "testinput.h"
|
||||
|
||||
/**
|
||||
* Main procedure for standalone fuzzing engine.
|
||||
*
|
||||
* Reads filenames from the argument array. For each filename, read the file
|
||||
* into memory and then call the fuzzing interface with the data.
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ii;
|
||||
for(ii = 1; ii < argc; ii++)
|
||||
{
|
||||
FILE *infile;
|
||||
printf("[%s] ", argv[ii]);
|
||||
|
||||
/* Try and open the file. */
|
||||
infile = fopen(argv[ii], "rb");
|
||||
if(infile)
|
||||
{
|
||||
uint8_t *buffer = NULL;
|
||||
size_t buffer_len;
|
||||
|
||||
printf("Opened.. ");
|
||||
|
||||
/* Get the length of the file. */
|
||||
fseek(infile, 0L, SEEK_END);
|
||||
buffer_len = ftell(infile);
|
||||
|
||||
/* Reset the file indicator to the beginning of the file. */
|
||||
fseek(infile, 0L, SEEK_SET);
|
||||
|
||||
/* Allocate a buffer for the file contents. */
|
||||
buffer = (uint8_t *)calloc(buffer_len, sizeof(uint8_t));
|
||||
if(buffer)
|
||||
{
|
||||
size_t result;
|
||||
|
||||
/* Read all the text from the file into the buffer. */
|
||||
result = fread(buffer, sizeof(uint8_t), buffer_len, infile);
|
||||
|
||||
if (result == buffer_len)
|
||||
{
|
||||
printf("Read %zu bytes, fuzzing.. ", buffer_len);
|
||||
/* Call the fuzzer with the data. */
|
||||
LLVMFuzzerTestOneInput(buffer, buffer_len);
|
||||
|
||||
printf("complete !!");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Failed to read %zu bytes (result %zu)\n",
|
||||
buffer_len,
|
||||
result);
|
||||
}
|
||||
|
||||
/* Free the buffer as it's no longer needed. */
|
||||
free(buffer);
|
||||
buffer = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,
|
||||
"[%s] Failed to allocate %zu bytes \n",
|
||||
argv[ii],
|
||||
buffer_len);
|
||||
}
|
||||
|
||||
/* Close the file as it's no longer needed. */
|
||||
fclose(infile);
|
||||
infile = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Failed to open the file. Maybe wrong name or wrong permissions? */
|
||||
fprintf(stderr, "[%s] Open failed. \n", argv[ii]);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
3
Engine/lib/libsndfile/ossfuzz/testinput.h
Normal file
3
Engine/lib/libsndfile/ossfuzz/testinput.h
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#include <inttypes.h>
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
|
||||
Loading…
Add table
Add a link
Reference in a new issue