Coverage Report

Created: 2025-07-01 06:33

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