Coverage Report

Created: 2025-07-11 06:48

/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
6.70k
         uint32_t flags) {
23
6.70k
 if (size < 2) {
24
2
   return;
25
2
 }
26
27
6.70k
 size_t mid = size / 2;
28
29
6.70k
 cmsHPROFILE hInProfile, hOutProfile;
30
6.70k
 cmsHTRANSFORM hTransform;
31
32
6.70k
 hInProfile = cmsOpenProfileFromMem(data, mid);
33
6.70k
 hOutProfile = cmsOpenProfileFromMem(data + mid, size - mid);
34
6.70k
 hTransform = cmsCreateTransform(hInProfile, input_format, hOutProfile,
35
6.70k
                                 output_format, intent_id, flags);
36
6.70k
 cmsCloseProfile(hInProfile);
37
6.70k
 cmsCloseProfile(hOutProfile);
38
39
6.70k
 if (hTransform) {
40
583
   cmsDeleteTransform(hTransform);
41
583
 }
42
6.70k
}
43
44
12.2k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
45
12.2k
 if (size < 16) {
46
11
  return 0;
47
11
 }
48
49
 // Generate a random set of args for cmsCreateTransform
50
12.2k
 uint32_t input_format  = *((const uint32_t *)data);
51
12.2k
 uint32_t output_format = *((const uint32_t *)data+1);
52
12.2k
 uint32_t flags         = *((const uint32_t *)data+2);
53
12.2k
 uint32_t intent        = *((const uint32_t *)data+3) % 16;
54
12.2k
 data += 16;
55
12.2k
 size -= 16;
56
57
12.2k
 run_test(data, size, intent, input_format, output_format, flags);
58
12.2k
 return 0;
59
12.2k
}