Coverage Report

Created: 2025-12-14 06:03

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