Debian Codegraph @

fuzzing/nal_fuzzer.cc

raw
1 /*
2 * H.265 video codec.
3 * Copyright (c) 2026 Dirk Farin <[email protected]>
4 *
5 * This file is part of libde265.
6 *
7 * libde265 is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * libde265 is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with libde265. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "de265.h"
22 #include <stdint.h>
23 #include <stddef.h>
24
25 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
26 {
27 de265_decoder_context* ctx = de265_new_decoder();
28 if (!ctx) {
29 return 0;
30 }
31
32 de265_set_parameter_bool(ctx, DE265_DECODER_PARAM_BOOL_SEI_CHECK_HASH, 0);
33 de265_set_parameter_bool(ctx, DE265_DECODER_PARAM_SUPPRESS_FAULTY_PICTURES, 0);
34 de265_set_parameter_int(ctx, DE265_DECODER_PARAM_ACCELERATION_CODE, de265_acceleration_SCALAR);
35
36 // Interpret input as a sequence of length-prefixed NAL units.
37 // Each NAL is preceded by a 4-byte big-endian length.
38 size_t pos = 0;
39 while (pos + 4 <= size) {
40 uint32_t nal_size = (uint32_t(data[pos]) << 24) |
41 (uint32_t(data[pos + 1]) << 16) |
42 (uint32_t(data[pos + 2]) << 8) |
43 uint32_t(data[pos + 3]);
44 pos += 4;
45
46 if (nal_size > size - pos) {
47 break;
48 }
49
50 de265_push_NAL(ctx, data + pos, nal_size, 0, nullptr);
51 pos += nal_size;
52 }
53
54 de265_flush_data(ctx);
55
56 int more = 1;
57 while (more) {
58 de265_error err = de265_decode(ctx, &more);
59 if (!more || (err != DE265_OK && err != DE265_ERROR_WAITING_FOR_INPUT_DATA)) {
60 break;
61 }
62
63 while (const de265_image* img = de265_get_next_picture(ctx)) {
64 (void)img;
65 }
66 }
67
68 de265_free_decoder(ctx);
69 return 0;
70 }