Coverage Report

Created: 2025-11-24 06:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cms_dict_fuzzer.c
Line
Count
Source
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 <stdlib.h>
15
#include "lcms2.h"
16
17
201
wchar_t* generateWideString(const char* characters, const uint8_t *data){
18
201
    if (!characters){
19
0
        return NULL;
20
0
    }
21
    
22
201
    char stringToWide[10];
23
2.01k
    for (int i = 0; i < 9; i++){
24
1.80k
        stringToWide[i] = characters[data[i] % 95];
25
1.80k
    }
26
201
    stringToWide[9] = '\0';
27
    
28
201
    int requiredSize = mbstowcs(NULL, stringToWide, 0);
29
201
    wchar_t* wideString = (wchar_t *)malloc((requiredSize + 1) * sizeof(wchar_t));
30
201
    mbstowcs(wideString, stringToWide, requiredSize + 1);
31
201
    return wideString;
32
201
}
33
34
76
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
35
76
    if (size < 27){
36
9
        return 0;
37
9
    }
38
39
67
    cmsContext context = cmsCreateContext(NULL, (void *)data);
40
67
    if (!context) {
41
0
        return 0;
42
0
    }
43
44
    // Create a Dictionary handle
45
67
    cmsHANDLE hDict = cmsDictAlloc(context);
46
67
    if (!hDict) {
47
0
        return 0;
48
0
    }
49
    
50
51
67
    cmsMLU *mlu = cmsMLUalloc(hDict, 0);
52
67
    if (!mlu) {
53
0
        return 0;
54
0
    }
55
    
56
67
    char* characters = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
57
67
    wchar_t* wideString = generateWideString(characters, data);
58
67
    cmsMLUsetWide(mlu, "en", "US", wideString);
59
67
    free(wideString);
60
    
61
    
62
67
    char ObtainedLanguage[3], ObtainedCountry[3];
63
67
    ObtainedLanguage[0] = characters[*(data+1) % 95];
64
67
    ObtainedLanguage[1] = characters[*(data+2) % 95];
65
67
    ObtainedLanguage[2] = characters[*(data) % 95];
66
67
67
    ObtainedCountry[0] = characters[*(data+2) % 95];
68
67
    ObtainedCountry[1] = characters[*data % 95];
69
67
    ObtainedCountry[2] = characters[*(data+1) % 95];
70
67
    cmsMLUgetTranslation(mlu, "en", "US",ObtainedLanguage,ObtainedCountry);
71
67
    cmsMLUtranslationsCount(mlu);
72
67
    cmsMLUtranslationsCodes(mlu, *((uint32_t *)data), ObtainedLanguage, ObtainedCountry);
73
74
67
    cmsMLU* displayName = mlu;
75
67
    cmsMLU* displayValue = mlu;
76
77
    //cmsDictAddEntry
78
67
    wchar_t* name = generateWideString(characters, data + 9);
79
67
    wchar_t* value = generateWideString(characters, data + 18);
80
67
    cmsDictAddEntry(hDict, name, value, displayName, displayValue);
81
67
    free(name);
82
67
    free(value);
83
84
    //cmsDictDup
85
67
    cmsHANDLE ResultDictDup = cmsDictDup(hDict);
86
67
    if (ResultDictDup) {
87
67
        cmsDictFree(ResultDictDup);
88
67
    }
89
    // Iterate over the Dictionary entries
90
67
    const cmsDICTentry* entry = cmsDictGetEntryList(hDict);
91
67
    cmsDictNextEntry(entry);
92
67
    cmsMLUfree(mlu);
93
67
    cmsDictFree(hDict);
94
67
    return 0;
95
67
}