/src/aom/examples/av1_dec_fuzzer.cc
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2019, Alliance for Open Media. All rights reserved. |
3 | | * |
4 | | * This source code is subject to the terms of the BSD 2 Clause License and |
5 | | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
6 | | * was not distributed with this source code in the LICENSE file, you can |
7 | | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
8 | | * Media Patent License 1.0 was not distributed with this source code in the |
9 | | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
10 | | */ |
11 | | |
12 | | /* |
13 | | * See build_av1_dec_fuzzer.sh for building instructions. |
14 | | */ |
15 | | |
16 | | #include <stddef.h> |
17 | | #include <stdint.h> |
18 | | #include <stdio.h> |
19 | | #include <stdlib.h> |
20 | | #include <algorithm> |
21 | | #include <memory> |
22 | | #include "config/aom_config.h" |
23 | | #include "aom/aom_decoder.h" |
24 | | #include "aom/aomdx.h" |
25 | | #include "aom_ports/mem_ops.h" |
26 | | |
27 | 892k | #define IVF_FRAME_HDR_SZ (4 + 8) /* 4 byte size + 8 byte timestamp */ |
28 | 145k | #define IVF_FILE_HDR_SZ 32 |
29 | | |
30 | 0 | extern "C" void usage_exit(void) { exit(EXIT_FAILURE); } |
31 | | |
32 | 16.1k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
33 | 16.1k | if (size <= IVF_FILE_HDR_SZ) { |
34 | 9 | return 0; |
35 | 9 | } |
36 | | |
37 | | // Abusing the four unused bytes at the end of the IVF file header as a source |
38 | | // of random bits. |
39 | 16.1k | unsigned int tile_mode = (data[IVF_FILE_HDR_SZ - 1] & 2) != 0; |
40 | 16.1k | unsigned int ext_tile_debug = (data[IVF_FILE_HDR_SZ - 1] & 4) != 0; |
41 | 16.1k | unsigned int is_annexb = (data[IVF_FILE_HDR_SZ - 1] & 8) != 0; |
42 | 16.1k | int output_all_layers = (data[IVF_FILE_HDR_SZ - 1] & 0x10) != 0; |
43 | 16.1k | int operating_point = data[IVF_FILE_HDR_SZ - 2] & 0x1F; |
44 | | |
45 | 16.1k | aom_codec_iface_t *codec_interface = aom_codec_av1_dx(); |
46 | 16.1k | aom_codec_ctx_t codec; |
47 | | // Set thread count in the range [1, 64]. |
48 | 16.1k | const unsigned int threads = (data[IVF_FILE_HDR_SZ] & 0x3f) + 1; |
49 | 16.1k | aom_codec_dec_cfg_t cfg = { threads, 0, 0, !FORCE_HIGHBITDEPTH_DECODING }; |
50 | 16.1k | if (aom_codec_dec_init(&codec, codec_interface, &cfg, 0)) { |
51 | 0 | return 0; |
52 | 0 | } |
53 | 16.1k | AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1_SET_TILE_MODE, tile_mode); |
54 | 16.1k | AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_EXT_TILE_DEBUG, ext_tile_debug); |
55 | 16.1k | AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_SET_IS_ANNEXB, is_annexb); |
56 | 16.1k | AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_SET_OUTPUT_ALL_LAYERS, |
57 | 16.1k | output_all_layers); |
58 | 16.1k | AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_SET_OPERATING_POINT, |
59 | 16.1k | operating_point); |
60 | | |
61 | 16.1k | data += IVF_FILE_HDR_SZ; |
62 | 16.1k | size -= IVF_FILE_HDR_SZ; |
63 | | |
64 | 308k | while (size > IVF_FRAME_HDR_SZ) { |
65 | 292k | size_t frame_size = mem_get_le32(data); |
66 | 292k | size -= IVF_FRAME_HDR_SZ; |
67 | 292k | data += IVF_FRAME_HDR_SZ; |
68 | 292k | frame_size = std::min(size, frame_size); |
69 | | |
70 | 292k | aom_codec_stream_info_t stream_info; |
71 | 292k | stream_info.is_annexb = is_annexb; |
72 | 292k | aom_codec_err_t err = |
73 | 292k | aom_codec_peek_stream_info(codec_interface, data, size, &stream_info); |
74 | 292k | static_cast<void>(err); |
75 | | |
76 | 292k | err = aom_codec_decode(&codec, data, frame_size, nullptr); |
77 | 292k | static_cast<void>(err); |
78 | 292k | aom_codec_iter_t iter = nullptr; |
79 | 292k | aom_image_t *img = nullptr; |
80 | 354k | while ((img = aom_codec_get_frame(&codec, &iter)) != nullptr) { |
81 | 62.4k | } |
82 | 292k | data += frame_size; |
83 | 292k | size -= frame_size; |
84 | 292k | } |
85 | 16.1k | aom_codec_destroy(&codec); |
86 | 16.1k | return 0; |
87 | 16.1k | } |