Commit 73067e5c authored by Janne Grunau's avatar Janne Grunau
Browse files

allocation fail fuzzer: use a static library and objcopy

oss-fuzz can not handle shared libraries. Do not build it by default.
parent a6b903fb
Pipeline #3487 passed with stages
in 4 minutes and 57 seconds
......@@ -44,23 +44,21 @@ void dav1d_setup_alloc_fail(unsigned seed, unsigned probability) {
fail_probability = probability;
void * __real_malloc(size_t);
void * __wrap_malloc(size_t);
void * __wrap_malloc(size_t sz) {
if (rand() < fail_probability)
return NULL;
return __real_malloc(sz);
return malloc(sz);
int __real_posix_memalign(void **memptr, size_t alignment, size_t size);
int __wrap_posix_memalign(void **memptr, size_t alignment, size_t size);
int __wrap_posix_memalign(void **memptr, size_t alignment, size_t size) {
if (rand() < fail_probability)
return ENOMEM;
return __real_posix_memalign(memptr, alignment, size);
return posix_memalign(memptr, alignment, size);
#error "HAVE_POSIX_MEMALIGN required"
......@@ -124,28 +124,29 @@ dav1d_fuzzer_mt = executable('dav1d_fuzzer_mt',
dependencies : [thread_dependency],
if (cc.has_function('posix_memalign', prefix : '#include <stdlib.h>', args : test_args) and
cc.has_link_argument('-Wl,-wrap,malloc') and not get_option('b_lto'))
alloc_fail = shared_library('alloc_fail',
objects: [
libdav1d.extract_all_objects(recursive: true),
include_directories: dav1d_inc_dirs,
c_args : [stackalign_flag],
link_args: ['-Wl,-wrap,malloc', '-Wl,-wrap,posix_memalign'],
dependencies : [thread_dependency],
objcopy = find_program('objcopy',
required: false)
if (objcopy.found() and
not get_option('b_lto') and
get_option('default_library') == 'static' and
cc.has_function('posix_memalign', prefix : '#include <stdlib.h>', args : test_args))
libdav1d_af = custom_target('libdav1d_af',
input: libdav1d,
output: 'libdav1d_af.a',
depends: libdav1d,
command: [objcopy,
'--redefine-sym', 'malloc=__wrap_malloc',
'--redefine-sym', 'posix_memalign=__wrap_posix_memalign',
'@INPUT@', '@OUTPUT@'])
dav1d_fuzzer_mem = executable('dav1d_fuzzer_mem',
dav1d_fuzzer_sources + ['libfuzzer/alloc_fail.c'],
include_directories: dav1d_inc_dirs,
c_args: [stackalign_flag, stackrealign_flag, '-DDAV1D_ALLOC_FAIL'],
link_args: fuzzer_ldflags,
link_with : [alloc_fail],
build_by_default: true,
link_args: fuzzer_ldflags + [join_paths(libdav1d_af.full_path())],
link_depends: libdav1d_af,
build_by_default: false,
dependencies : [thread_dependency],
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment