2018-06-12 01:27:33 +00:00
|
|
|
// Fuzzing of AV1 decoder.
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2018-07-24 00:53:34 +00:00
|
|
|
#include <memory>
|
2018-06-12 01:27:33 +00:00
|
|
|
|
|
|
|
#include "aom/aom_decoder.h"
|
|
|
|
#include "aom/aomdx.h"
|
|
|
|
#include "aom_ports/mem_ops.h"
|
2018-06-20 15:00:55 +00:00
|
|
|
#include "common/ivfdec.h"
|
2018-06-12 01:27:33 +00:00
|
|
|
|
2018-07-24 00:53:34 +00:00
|
|
|
static void close_file(FILE *file) { fclose(file); }
|
|
|
|
|
2018-06-12 01:27:33 +00:00
|
|
|
extern "C" void usage_exit(void) { exit(EXIT_FAILURE); }
|
|
|
|
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
2018-07-24 00:53:34 +00:00
|
|
|
std::unique_ptr<FILE, decltype(&close_file)> file(
|
|
|
|
fmemopen((void *)data, size, "rb"), &close_file);
|
2018-06-12 01:27:33 +00:00
|
|
|
if (file == nullptr) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char header[32];
|
2018-07-24 00:53:34 +00:00
|
|
|
if (fread(header, 1, 32, file.get()) != 32) {
|
2018-06-12 01:27:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
const AvxInterface *decoder = get_aom_decoder_by_name("av1");
|
|
|
|
if (decoder == nullptr) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
aom_codec_ctx_t codec;
|
2018-06-12 20:00:26 +00:00
|
|
|
#if defined(DECODE_MODE)
|
2018-06-12 01:27:33 +00:00
|
|
|
const int threads = 1;
|
|
|
|
#elif defined(DECODE_MODE_threaded)
|
|
|
|
const int threads = 16;
|
|
|
|
#else
|
2018-06-12 20:00:26 +00:00
|
|
|
#error define one of DECODE_MODE or DECODE_MODE_threaded
|
2018-06-12 01:27:33 +00:00
|
|
|
#endif
|
|
|
|
aom_codec_dec_cfg_t cfg = {threads, 0, 0};
|
|
|
|
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;
|
2018-07-24 00:53:34 +00:00
|
|
|
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);
|
2018-09-15 21:29:05 +00:00
|
|
|
static_cast<void>(err);
|
2018-06-12 01:27:33 +00:00
|
|
|
aom_codec_iter_t iter = nullptr;
|
|
|
|
aom_image_t *img = nullptr;
|
|
|
|
while ((img = aom_codec_get_frame(&codec, &iter)) != nullptr) {
|
|
|
|
}
|
|
|
|
}
|
2018-06-29 23:19:45 +00:00
|
|
|
aom_codec_destroy(&codec);
|
2018-06-12 01:27:33 +00:00
|
|
|
free(buffer);
|
|
|
|
return 0;
|
|
|
|
}
|