/src/grok/tests/fuzzers/grk_decompress_fuzzer.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 2016-2026 Grok Image Compression Inc. |
3 | | * |
4 | | * This source code is free software: you can redistribute it and/or modify |
5 | | * it under the terms of the GNU Affero General Public License, version 3, |
6 | | * as published by the Free Software Foundation. |
7 | | * |
8 | | * This source code is distributed in the hope that it will be useful, |
9 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | | * GNU Affero General Public License for more details. |
12 | | * |
13 | | * You should have received a copy of the GNU Affero General Public License |
14 | | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | | * |
16 | | */ |
17 | | |
18 | | #include <climits> |
19 | | #include <cstddef> |
20 | | #include <cstdint> |
21 | | #include <cstring> |
22 | | #include "grok.h" |
23 | | |
24 | | extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv); |
25 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* buf, size_t len); |
26 | | struct Initializer |
27 | | { |
28 | | Initializer() |
29 | 2 | { |
30 | 2 | grk_initialize(nullptr, 0, nullptr); |
31 | 2 | } |
32 | | }; |
33 | | int LLVMFuzzerInitialize(int* argc, char*** argv) |
34 | 2 | { |
35 | 2 | static Initializer init; |
36 | 2 | return 0; |
37 | 2 | } |
38 | | int LLVMFuzzerTestOneInput(const uint8_t* buf, size_t len) |
39 | 126 | { |
40 | 126 | grk_header_info headerInfo = {}; |
41 | 126 | grk_decompress_parameters parameters = {}; |
42 | 126 | parameters.dw_x1 = 1024; |
43 | 126 | parameters.dw_y1 = 1024; |
44 | 126 | grk_object* codec = nullptr; |
45 | 126 | grk_stream_params stream_params = {}; |
46 | 126 | stream_params.buf = const_cast<uint8_t*>(buf); |
47 | 126 | stream_params.buf_len = len; |
48 | 126 | codec = grk_decompress_init(&stream_params, ¶meters); |
49 | 126 | if(!codec) |
50 | 1 | goto cleanup; |
51 | 125 | if(!grk_decompress_read_header(codec, &headerInfo)) |
52 | 2 | goto cleanup; |
53 | 123 | if(!grk_decompress(codec, nullptr)) |
54 | 18 | goto cleanup; |
55 | 126 | cleanup: |
56 | 126 | grk_object_unref(codec); |
57 | | |
58 | 126 | return 0; |
59 | 123 | } |