Coverage Report

Created: 2025-07-01 06:35

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