Coverage Report

Created: 2023-03-26 07:03

/src/utf8proc/test/fuzzer.c
Line
Count
Source (jump to first uncovered line)
1
#include <utf8proc.h>
2
#include <string.h>
3
4
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
5
1.27k
{
6
1.27k
    if(size < 1) return 0;
7
8
    /* Avoid timeout with long inputs */
9
1.27k
    if(size > (64 * 1024)) return 0;
10
11
1.26k
    if(data[size-1] != '\0') return 0;
12
13
1.24k
    const uint8_t* ptr = data;
14
1.24k
    utf8proc_int32_t c = 0, c_prev = 0, state = 0;
15
1.24k
    utf8proc_option_t options;
16
1.24k
    utf8proc_ssize_t ret, bytes = 0;
17
1.24k
    size_t len = strlen((const char*)data);
18
    
19
774k
    while(bytes != len)
20
773k
    {
21
773k
        ret = utf8proc_iterate(ptr, -1, &c);
22
        
23
773k
        if(ret < 0 || ret == 0) break;
24
        
25
773k
        bytes += ret;
26
773k
        ptr += ret;
27
28
773k
        utf8proc_tolower(c);
29
773k
        utf8proc_toupper(c);
30
773k
        utf8proc_totitle(c);
31
773k
        utf8proc_islower(c);
32
773k
        utf8proc_isupper(c);
33
773k
        utf8proc_charwidth(c);
34
773k
        utf8proc_category(c);
35
773k
        utf8proc_category_string(c);
36
773k
        utf8proc_codepoint_valid(c);
37
        
38
773k
        utf8proc_grapheme_break(c_prev, c);
39
773k
        utf8proc_grapheme_break_stateful(c_prev, c, &state);
40
        
41
773k
        c_prev = c;
42
773k
    }
43
    
44
1.24k
    utf8proc_int32_t *copy = size >= 4 ? NULL : malloc(size);
45
    
46
1.24k
    if(copy)
47
142
    {
48
142
        size /= 4;
49
        
50
142
        options = UTF8PROC_STRIPCC | UTF8PROC_NLF2LS | UTF8PROC_NLF2PS;
51
142
        memcpy(copy, data, size);
52
142
        utf8proc_normalize_utf32(copy, size, options);
53
        
54
142
        options = UTF8PROC_STRIPCC | UTF8PROC_NLF2LS;
55
142
        memcpy(copy, data, size);
56
142
        utf8proc_normalize_utf32(copy, size, options);
57
        
58
142
        options = UTF8PROC_STRIPCC | UTF8PROC_NLF2PS;
59
142
        memcpy(copy, data, size);
60
142
        utf8proc_normalize_utf32(copy, size, options);
61
        
62
142
        options = UTF8PROC_STRIPCC;
63
142
        memcpy(copy, data, size);
64
142
        utf8proc_normalize_utf32(copy, size, options);
65
66
142
        options = UTF8PROC_LUMP;
67
142
        memcpy(copy, data, size);
68
142
        utf8proc_normalize_utf32(copy, size, options);
69
70
142
        options = 0;
71
142
        memcpy(copy, data, size);
72
142
        utf8proc_normalize_utf32(copy, size, options);
73
        
74
142
        free(copy);
75
142
    }
76
77
1.24k
    free(utf8proc_NFD(data));
78
1.24k
    free(utf8proc_NFC(data));
79
1.24k
    free(utf8proc_NFKD(data));
80
1.24k
    free(utf8proc_NFKC(data));
81
1.24k
    free(utf8proc_NFKC_Casefold(data));
82
83
1.24k
    return 0;
84
1.26k
}