elliottk | a24f145 | 2019-01-21 00:25:12 -0800 | [diff] [blame] | 1 | /* |
Krishna Rapaka | 7319db5 | 2021-09-28 20:35:29 -0700 | [diff] [blame] | 2 | * Copyright (c) 2021, Alliance for Open Media. All rights reserved |
elliottk | a24f145 | 2019-01-21 00:25:12 -0800 | [diff] [blame] | 3 | * |
Vibhoothi | 41c6dd7 | 2021-10-12 18:48:26 +0000 | [diff] [blame] | 4 | * 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/. |
elliottk | a24f145 | 2019-01-21 00:25:12 -0800 | [diff] [blame] | 11 | */ |
| 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 Mahendrakar | 3c2da21 | 2019-06-12 13:41:02 -0700 | [diff] [blame] | 21 | #include <algorithm> |
elliottk | a24f145 | 2019-01-21 00:25:12 -0800 | [diff] [blame] | 22 | #include <memory> |
elliottk | a24f145 | 2019-01-21 00:25:12 -0800 | [diff] [blame] | 23 | #include "config/aom_config.h" |
| 24 | #include "aom/aom_decoder.h" |
| 25 | #include "aom/aomdx.h" |
| 26 | #include "aom_ports/mem_ops.h" |
Harish Mahendrakar | 338f1e6 | 2019-06-11 15:46:08 -0700 | [diff] [blame] | 27 | |
| 28 | #define IVF_FRAME_HDR_SZ (4 + 8) /* 4 byte size + 8 byte timestamp */ |
| 29 | #define IVF_FILE_HDR_SZ 32 |
elliottk | a24f145 | 2019-01-21 00:25:12 -0800 | [diff] [blame] | 30 | |
elliottk | a24f145 | 2019-01-21 00:25:12 -0800 | [diff] [blame] | 31 | extern "C" void usage_exit(void) { exit(EXIT_FAILURE); } |
| 32 | |
| 33 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
Harish Mahendrakar | 3c2da21 | 2019-06-12 13:41:02 -0700 | [diff] [blame] | 34 | if (size <= IVF_FILE_HDR_SZ) { |
elliottk | a24f145 | 2019-01-21 00:25:12 -0800 | [diff] [blame] | 35 | return 0; |
| 36 | } |
elliottk | a24f145 | 2019-01-21 00:25:12 -0800 | [diff] [blame] | 37 | |
Elliott Karpilovsky | 67e84d4 | 2020-04-26 16:03:39 -0700 | [diff] [blame] | 38 | aom_codec_iface_t *codec_interface = aom_codec_av1_dx(); |
elliottk | a24f145 | 2019-01-21 00:25:12 -0800 | [diff] [blame] | 39 | aom_codec_ctx_t codec; |
| 40 | // Set thread count in the range [1, 64]. |
Harish Mahendrakar | 8526a42 | 2019-06-14 10:27:19 -0700 | [diff] [blame] | 41 | const unsigned int threads = (data[IVF_FILE_HDR_SZ] & 0x3f) + 1; |
James Almer | 857e93f | 2022-05-25 16:44:43 +0000 | [diff] [blame] | 42 | aom_codec_dec_cfg_t cfg = { threads, 0, 0 }; |
Harish Mahendrakar | 338f1e6 | 2019-06-11 15:46:08 -0700 | [diff] [blame] | 43 | if (aom_codec_dec_init(&codec, codec_interface, &cfg, 0)) { |
elliottk | a24f145 | 2019-01-21 00:25:12 -0800 | [diff] [blame] | 44 | return 0; |
| 45 | } |
| 46 | |
Harish Mahendrakar | 3c2da21 | 2019-06-12 13:41:02 -0700 | [diff] [blame] | 47 | 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 | |
elliottk | a24f145 | 2019-01-21 00:25:12 -0800 | [diff] [blame] | 56 | const aom_codec_err_t err = |
Harish Mahendrakar | 3c2da21 | 2019-06-12 13:41:02 -0700 | [diff] [blame] | 57 | aom_codec_decode(&codec, data, frame_size, nullptr); |
elliottk | a24f145 | 2019-01-21 00:25:12 -0800 | [diff] [blame] | 58 | 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 Mahendrakar | 3c2da21 | 2019-06-12 13:41:02 -0700 | [diff] [blame] | 63 | data += frame_size; |
| 64 | size -= frame_size; |
elliottk | a24f145 | 2019-01-21 00:25:12 -0800 | [diff] [blame] | 65 | } |
| 66 | aom_codec_destroy(&codec); |
elliottk | a24f145 | 2019-01-21 00:25:12 -0800 | [diff] [blame] | 67 | return 0; |
| 68 | } |