From 9e3ec89cf2961cb0f8fd189e9c19b7b23538961f Mon Sep 17 00:00:00 2001 From: Harish Mahendrakar Date: Fri, 14 Jun 2019 08:29:20 -0700 Subject: [PATCH] [libaom] Use fuzzer plugin source from libaom repository (#2515) Removed av1_dec_fuzzer.cc from projects/libaom and instead using from libaom repository BUG=https://crbug.com/aomedia/2257 --- projects/libaom/Dockerfile | 2 +- projects/libaom/av1_dec_fuzzer.cc | 68 ------------------------------- projects/libaom/build.sh | 41 ++++++------------- 3 files changed, 13 insertions(+), 98 deletions(-) delete mode 100644 projects/libaom/av1_dec_fuzzer.cc diff --git a/projects/libaom/Dockerfile b/projects/libaom/Dockerfile index 9b67f332e..0619ac065 100644 --- a/projects/libaom/Dockerfile +++ b/projects/libaom/Dockerfile @@ -19,5 +19,5 @@ MAINTAINER urvang@google.com RUN apt-get update && apt-get install -y cmake yasm wget RUN git clone https://aomedia.googlesource.com/aom ADD https://storage.googleapis.com/aom-test-data/fuzzer/dec_fuzzer_seed_corpus.zip $SRC/ -COPY build.sh av1_dec_fuzzer.cc av1_dec_fuzzer.dict $SRC/ +COPY build.sh av1_dec_fuzzer.dict $SRC/ WORKDIR aom diff --git a/projects/libaom/av1_dec_fuzzer.cc b/projects/libaom/av1_dec_fuzzer.cc deleted file mode 100644 index b5630fe56..000000000 --- a/projects/libaom/av1_dec_fuzzer.cc +++ /dev/null @@ -1,68 +0,0 @@ -// Fuzzing of AV1 decoder. - -#include -#include -#include -#include -#if defined(DECODE_MODE_threaded) -#include -#endif -#include - -#include "config/aom_config.h" -#include "aom/aom_decoder.h" -#include "aom/aomdx.h" -#include "aom_ports/mem_ops.h" -#include "common/ivfdec.h" - -static void close_file(FILE *file) { fclose(file); } - -extern "C" void usage_exit(void) { exit(EXIT_FAILURE); } - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - std::unique_ptr file( - fmemopen((void *)data, size, "rb"), &close_file); - if (file == nullptr) { - return 0; - } - - char header[32]; - if (fread(header, 1, 32, file.get()) != 32) { - return 0; - } - const AvxInterface *decoder = get_aom_decoder_by_name("av1"); - if (decoder == nullptr) { - return 0; - } - - aom_codec_ctx_t codec; -#if defined(DECODE_MODE) - const unsigned int threads = 1; -#elif defined(DECODE_MODE_threaded) - // Set thread count in the range [2, 64]. - const unsigned int threads = std::max((header[0] & 0x3f) + 1, 2); -#else -#error define one of DECODE_MODE or DECODE_MODE_threaded -#endif - aom_codec_dec_cfg_t cfg = {threads, 0, 0, CONFIG_LOWBITDEPTH}; - if (aom_codec_dec_init(&codec, decoder->codec_interface(), &cfg, 0)) { - return 0; - } - - uint8_t *buffer = nullptr; - size_t buffer_size = 0; - size_t frame_size = 0; - while (!ivf_read_frame(file.get(), &buffer, &frame_size, &buffer_size, - nullptr)) { - const aom_codec_err_t err = - aom_codec_decode(&codec, buffer, frame_size, nullptr); - static_cast(err); - aom_codec_iter_t iter = nullptr; - aom_image_t *img = nullptr; - while ((img = aom_codec_get_frame(&codec, &iter)) != nullptr) { - } - } - aom_codec_destroy(&codec); - free(buffer); - return 0; -} diff --git a/projects/libaom/build.sh b/projects/libaom/build.sh index 522a151c4..fc25bbf4c 100755 --- a/projects/libaom/build.sh +++ b/projects/libaom/build.sh @@ -43,8 +43,7 @@ if [[ $CFLAGS = *sanitize=memory* ]]; then fi cmake $SRC/aom -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE='-O3 -g' \ - -DCMAKE_CXX_FLAGS_RELEASE='-O3 -g' -DCMAKE_LD_FLAGS_RELEASE='-O3 -g' \ - -DCONFIG_PIC=1 -DCONFIG_SCALABILITY=0 -DCONFIG_LOWBITDEPTH=1 \ + -DCMAKE_CXX_FLAGS_RELEASE='-O3 -g' -DCONFIG_PIC=1 -DCONFIG_LOWBITDEPTH=1 \ -DCONFIG_AV1_ENCODER=0 -DENABLE_EXAMPLES=0 -DENABLE_DOCS=0 -DENABLE_TESTS=0 \ -DCONFIG_SIZE_LIMIT=1 -DDECODE_HEIGHT_LIMIT=12288 -DDECODE_WIDTH_LIMIT=12288 \ -DAOM_EXTRA_C_FLAGS="${extra_c_flags}" \ @@ -52,35 +51,19 @@ cmake $SRC/aom -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE='-O3 -g' \ make -j$(nproc) popd -# Build some libaom utils that are not part of the core lib. -$CC $CFLAGS -std=c99 -c \ - -I$SRC/aom \ - -I${build_dir} \ - $SRC/aom/common/ivfdec.c -o ${build_dir}/ivfdec.o - -$CC $CFLAGS -std=c99 -c \ - -I$SRC/aom \ - -I${build_dir} \ - $SRC/aom/common/tools_common.c -o ${build_dir}/tools_common.o - # build fuzzers fuzzer_src_name=av1_dec_fuzzer -fuzzer_modes=( '' '_threaded' ) +fuzzer_name=${fuzzer_src_name} -for mode in "${fuzzer_modes[@]}"; do - fuzzer_name=${fuzzer_src_name}${mode} +$CXX $CXXFLAGS -std=c++11 \ + -I$SRC/aom \ + -I${build_dir} \ + -Wl,--start-group \ + $LIB_FUZZING_ENGINE \ + $SRC/aom/examples/${fuzzer_src_name}.cc -o $OUT/${fuzzer_name} \ + ${build_dir}/libaom.a -Wl,--end-group - $CXX $CXXFLAGS -std=c++11 \ - -DDECODE_MODE${mode} \ - -I$SRC/aom \ - -I${build_dir} \ - -Wl,--start-group \ - $LIB_FUZZING_ENGINE \ - $SRC/${fuzzer_src_name}.cc -o $OUT/${fuzzer_name} \ - ${build_dir}/libaom.a ${build_dir}/ivfdec.o ${build_dir}/tools_common.o \ - -Wl,--end-group +# copy seed corpus. +cp $SRC/dec_fuzzer_seed_corpus.zip $OUT/${fuzzer_name}_seed_corpus.zip +cp $SRC/av1_dec_fuzzer.dict $OUT/${fuzzer_name}.dict - # copy seed corpus. - cp $SRC/dec_fuzzer_seed_corpus.zip $OUT/${fuzzer_name}_seed_corpus.zip - cp $SRC/av1_dec_fuzzer.dict $OUT/${fuzzer_name}.dict -done