#ifndef FLAC__SHARE__ALLOC_H
#define FLAC__SHARE__ALLOC_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <limits.h>
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#include <stdlib.h>
#include "share/compat.h"
#ifndef SIZE_MAX
#ifndef SIZE_T_MAX
#ifdef _MSC_VER
#ifdef _WIN64
#define SIZE_T_MAX …
#else
#define SIZE_T_MAX …
#endif
#else
#error
#endif
#endif
#define SIZE_MAX …
#endif
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
extern int alloc_check_threshold, alloc_check_counter;
static inline int alloc_check() {
if (alloc_check_threshold == INT32_MAX) {
return 0;
} else if (alloc_check_counter++ == alloc_check_threshold) {
return 1;
} else {
return 0;
}
}
#endif
static inline void* safe_malloc_(size_t size) { … }
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
static inline void* malloc_(size_t size) {
if (alloc_check()) {
return NULL;
}
return malloc(size);
}
#else
#define malloc_ …
#endif
static inline void* safe_calloc_(size_t nmemb, size_t size) { … }
static inline void* safe_malloc_add_2op_(size_t size1, size_t size2) { … }
static inline void* safe_malloc_add_3op_(size_t size1,
size_t size2,
size_t size3) { … }
static inline void* safe_malloc_add_4op_(size_t size1,
size_t size2,
size_t size3,
size_t size4) { … }
void* safe_malloc_mul_2op_(size_t size1, size_t size2);
static inline void* safe_malloc_mul_3op_(size_t size1,
size_t size2,
size_t size3) { … }
static inline void* safe_malloc_mul2add_(size_t size1,
size_t size2,
size_t size3) { … }
static inline void* safe_malloc_muladd2_(size_t size1,
size_t size2,
size_t size3) { … }
static inline void* safe_realloc_(void* ptr, size_t size) { … }
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
static inline void* realloc_(void* ptr, size_t size) {
if (alloc_check()) {
return NULL;
}
return realloc(ptr, size);
}
#else
#define realloc_ …
#endif
static inline void* safe_realloc_nofree_add_2op_(void* ptr,
size_t size1,
size_t size2) { … }
static inline void* safe_realloc_add_3op_(void* ptr,
size_t size1,
size_t size2,
size_t size3) { … }
static inline void* safe_realloc_nofree_add_3op_(void* ptr,
size_t size1,
size_t size2,
size_t size3) { … }
static inline void* safe_realloc_nofree_add_4op_(void* ptr,
size_t size1,
size_t size2,
size_t size3,
size_t size4) { … }
static inline void* safe_realloc_mul_2op_(void* ptr,
size_t size1,
size_t size2) { … }
static inline void* safe_realloc_nofree_mul_2op_(void* ptr,
size_t size1,
size_t size2) { … }
static inline void* safe_realloc_muladd2_(void* ptr,
size_t size1,
size_t size2,
size_t size3) { … }
static inline void* safe_realloc_nofree_muladd2_(void* ptr,
size_t size1,
size_t size2,
size_t size3) { … }
#endif