blob: 74caf38e2e7e965fe02a2e4c1c18ee54b16f20a9 [file] [log] [blame]
elliottka24f1452019-01-21 00:25:12 -08001/*
Krishna Rapaka7319db52021-09-28 20:35:29 -07002 * Copyright (c) 2021, Alliance for Open Media. All rights reserved
elliottka24f1452019-01-21 00:25:12 -08003 *
Vibhoothi41c6dd72021-10-12 18:48:26 +00004 * This source code is subject to the terms of the BSD 3-Clause Clear License
5 * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
6 * License was not distributed with this source code in the LICENSE file, you
7 * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/. If the
8 * Alliance for Open Media Patent License 1.0 was not distributed with this
9 * source code in the PATENTS file, you can obtain it at
10 * aomedia.org/license/patent-license/.
elliottka24f1452019-01-21 00:25:12 -080011 */
12
13/*
14 * See build_av1_dec_fuzzer.sh for building instructions.
15 */
16
17#include <stddef.h>
18#include <stdint.h>
19#include <stdio.h>
20#include <stdlib.h>
Harish Mahendrakar3c2da212019-06-12 13:41:02 -070021#include <algorithm>
elliottka24f1452019-01-21 00:25:12 -080022#include <memory>
elliottka24f1452019-01-21 00:25:12 -080023#include "config/aom_config.h"
24#include "aom/aom_decoder.h"
25#include "aom/aomdx.h"
26#include "aom_ports/mem_ops.h"
Harish Mahendrakar338f1e62019-06-11 15:46:08 -070027
28#define IVF_FRAME_HDR_SZ (4 + 8) /* 4 byte size + 8 byte timestamp */
29#define IVF_FILE_HDR_SZ 32
elliottka24f1452019-01-21 00:25:12 -080030
elliottka24f1452019-01-21 00:25:12 -080031extern "C" void usage_exit(void) { exit(EXIT_FAILURE); }
32
33extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
Harish Mahendrakar3c2da212019-06-12 13:41:02 -070034 if (size <= IVF_FILE_HDR_SZ) {
elliottka24f1452019-01-21 00:25:12 -080035 return 0;
36 }
elliottka24f1452019-01-21 00:25:12 -080037
Elliott Karpilovsky67e84d42020-04-26 16:03:39 -070038 aom_codec_iface_t *codec_interface = aom_codec_av1_dx();
elliottka24f1452019-01-21 00:25:12 -080039 aom_codec_ctx_t codec;
40 // Set thread count in the range [1, 64].
Harish Mahendrakar8526a422019-06-14 10:27:19 -070041 const unsigned int threads = (data[IVF_FILE_HDR_SZ] & 0x3f) + 1;
James Almer857e93f2022-05-25 16:44:43 +000042 aom_codec_dec_cfg_t cfg = { threads, 0, 0 };
Harish Mahendrakar338f1e62019-06-11 15:46:08 -070043 if (aom_codec_dec_init(&codec, codec_interface, &cfg, 0)) {
elliottka24f1452019-01-21 00:25:12 -080044 return 0;
45 }
46
Harish Mahendrakar3c2da212019-06-12 13:41:02 -070047 data += IVF_FILE_HDR_SZ;
48 size -= IVF_FILE_HDR_SZ;
49
50 while (size > IVF_FRAME_HDR_SZ) {
51 size_t frame_size = mem_get_le32(data);
52 size -= IVF_FRAME_HDR_SZ;
53 data += IVF_FRAME_HDR_SZ;
54 frame_size = std::min(size, frame_size);
55
elliottka24f1452019-01-21 00:25:12 -080056 const aom_codec_err_t err =
Harish Mahendrakar3c2da212019-06-12 13:41:02 -070057 aom_codec_decode(&codec, data, frame_size, nullptr);
elliottka24f1452019-01-21 00:25:12 -080058 static_cast<void>(err);
59 aom_codec_iter_t iter = nullptr;
60 aom_image_t *img = nullptr;
61 while ((img = aom_codec_get_frame(&codec, &iter)) != nullptr) {
62 }
Harish Mahendrakar3c2da212019-06-12 13:41:02 -070063 data += frame_size;
64 size -= frame_size;
elliottka24f1452019-01-21 00:25:12 -080065 }
66 aom_codec_destroy(&codec);
elliottka24f1452019-01-21 00:25:12 -080067 return 0;
68}