Coverage Report

Created: 2026-04-03 06:44

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