Coverage Report

Created: 2026-01-10 06:11

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