/src/cms_transform_all_fuzzer.c
Line | Count | Source |
1 | | /* Copyright 2022 Google LLC |
2 | | Licensed under the Apache License, Version 2.0 (the "License"); |
3 | | you may not use this file except in compliance with the License. |
4 | | You may obtain a copy of the License at |
5 | | http://www.apache.org/licenses/LICENSE-2.0 |
6 | | Unless required by applicable law or agreed to in writing, software |
7 | | distributed under the License is distributed on an "AS IS" BASIS, |
8 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
9 | | See the License for the specific language governing permissions and |
10 | | limitations under the License. |
11 | | */ |
12 | | |
13 | | #include <stdint.h> |
14 | | #include "lcms2.h" |
15 | | |
16 | | void |
17 | | run_test(const uint8_t *data, |
18 | | size_t size, |
19 | | uint32_t intent_id, |
20 | | uint32_t input_format, |
21 | | uint32_t output_format, |
22 | 7.54k | uint32_t flags) { |
23 | 7.54k | if (size < 2) { |
24 | 2 | return; |
25 | 2 | } |
26 | | |
27 | 7.54k | size_t mid = size / 2; |
28 | | |
29 | 7.54k | cmsHPROFILE hInProfile, hOutProfile; |
30 | 7.54k | cmsHTRANSFORM hTransform; |
31 | | |
32 | 7.54k | hInProfile = cmsOpenProfileFromMem(data, mid); |
33 | 7.54k | hOutProfile = cmsOpenProfileFromMem(data + mid, size - mid); |
34 | 7.54k | hTransform = cmsCreateTransform(hInProfile, input_format, hOutProfile, |
35 | 7.54k | output_format, intent_id, flags); |
36 | 7.54k | cmsCloseProfile(hInProfile); |
37 | 7.54k | cmsCloseProfile(hOutProfile); |
38 | | |
39 | 7.54k | if (hTransform) { |
40 | 681 | cmsDeleteTransform(hTransform); |
41 | 681 | } |
42 | 7.54k | } |
43 | | |
44 | 13.3k | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
45 | 13.3k | if (size < 16) { |
46 | 12 | return 0; |
47 | 12 | } |
48 | | |
49 | | // Generate a random set of args for cmsCreateTransform |
50 | 13.3k | uint32_t input_format = *((const uint32_t *)data); |
51 | 13.3k | uint32_t output_format = *((const uint32_t *)data+1); |
52 | 13.3k | uint32_t flags = *((const uint32_t *)data+2); |
53 | 13.3k | uint32_t intent = *((const uint32_t *)data+3) % 16; |
54 | 13.3k | data += 16; |
55 | 13.3k | size -= 16; |
56 | | |
57 | 13.3k | run_test(data, size, intent, input_format, output_format, flags); |
58 | 13.3k | return 0; |
59 | 13.3k | } |