Coverage Report

Created: 2025-09-05 06:40

/src/cms_cgats_fuzzer.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright 2023 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
17
238
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
18
19
238
    if (size < 8){
20
4
        return 0;
21
4
    }
22
23
234
    cmsContext context = cmsCreateContext(NULL, (void *)data);
24
25
234
    uint32_t Row = *((uint32_t *)data);
26
234
    uint32_t Col = *((uint32_t *)data+1);
27
28
    /* Write */
29
234
    cmsHANDLE  it8;
30
234
    cmsInt32Number i;
31
32
234
    it8 = cmsIT8Alloc(0);
33
234
    if (it8 == NULL) return 0;
34
35
234
    cmsIT8SetSheetType(it8, "LCMS/TESTING");
36
234
    cmsIT8SetPropertyStr(it8, "ORIGINATOR",   "1 2 3 4");
37
234
    cmsIT8SetPropertyUncooked(it8, "DESCRIPTOR",   "1234");
38
234
    cmsIT8SetPropertyStr(it8, "MANUFACTURER", "3");
39
234
    cmsIT8SetPropertyDbl(it8, "CREATED",     data[0] / 255.0);
40
234
    cmsIT8SetPropertyDbl(it8, "SERIAL",      data[1] / 255.0);
41
234
    cmsIT8SetPropertyHex(it8, "MATERIAL",     0x123);
42
43
234
    cmsIT8SetPropertyDbl(it8, "NUMBER_OF_SETS", 10);
44
234
    cmsIT8SetPropertyDbl(it8, "NUMBER_OF_FIELDS", Row);
45
46
234
    cmsIT8SetDataFormat(it8, 0, "SAMPLE_ID");
47
234
    cmsIT8SetDataFormat(it8, 1, "RGB_R");
48
234
    cmsIT8SetDataFormat(it8, 2, "RGB_G");
49
234
    cmsIT8SetDataFormat(it8, 3, "RGB_B");
50
51
2.57k
    for (i=0; i < 10; i++) {
52
53
2.34k
          char Patch[20];
54
55
2.34k
          sprintf(Patch, "P%d", i);
56
57
2.34k
          cmsIT8SetDataRowCol(it8, i, 0, Patch);
58
2.34k
          cmsIT8SetDataRowColDbl(it8, i, 1, i);
59
2.34k
          cmsIT8SetDataRowColDbl(it8, i, 2, i);
60
2.34k
          cmsIT8SetDataRowColDbl(it8, i, 3, i);
61
2.34k
    }
62
63
234
    cmsIT8SaveToFile(it8, "TEST.IT8");
64
234
    cmsIT8Free(it8);
65
66
234
    it8 = cmsIT8LoadFromFile(0, "TEST.IT8");
67
234
    if (it8 == NULL) return 0;
68
69
    /* Read */
70
65
    cmsIT8GetDataRowColDbl(it8,Row,Col);
71
65
    cmsIT8GetPropertyDbl(it8, "DESCRIPTOR");
72
65
    cmsIT8GetDataDbl(it8, "P3", "RGB_G");
73
74
65
    cmsIT8Free(it8);
75
65
    return 1;
76
234
}