Coverage Report

Created: 2026-12-01 06:26

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.13k
{
6
2.13k
    if(size < 1) return 0;
7
8
    /* Avoid timeout with long inputs */
9
2.13k
    if(size > (64 * 1024)) return 0;
10
11
2.12k
    if(data[size-1] != '\0') return 0;
12
13
2.11k
    const uint8_t* ptr = data;
14
2.11k
    utf8proc_int32_t c = 0, c_prev = 0, state = 0;
15
2.11k
    unsigned int options;
16
2.11k
    utf8proc_ssize_t ret, bytes = 0;
17
2.11k
    utf8proc_uint8_t *str = NULL;
18
2.11k
    size_t len = strlen((const char*)data);
19
20
1.06M
    while(bytes != len)
21
1.06M
    {
22
1.06M
        ret = utf8proc_iterate(ptr, -1, &c);
23
24
1.06M
        if(ret < 0 || ret == 0) break;
25
26
1.06M
        bytes += ret;
27
1.06M
        ptr += ret;
28
29
1.06M
        utf8proc_tolower(c);
30
1.06M
        utf8proc_toupper(c);
31
1.06M
        utf8proc_totitle(c);
32
1.06M
        utf8proc_islower(c);
33
1.06M
        utf8proc_isupper(c);
34
1.06M
        utf8proc_charwidth(c);
35
1.06M
        utf8proc_category(c);
36
1.06M
        utf8proc_category_string(c);
37
1.06M
        utf8proc_codepoint_valid(c);
38
39
1.06M
        utf8proc_grapheme_break(c_prev, c);
40
1.06M
        utf8proc_grapheme_break_stateful(c_prev, c, &state);
41
42
1.06M
        c_prev = c;
43
1.06M
    }
44
45
2.11k
    utf8proc_int32_t *copy = size >= 4 ? malloc(size) : NULL;
46
47
2.11k
    if(copy)
48
1.82k
    {
49
1.82k
        size /= 4; /* number of utf8proc_int32_t code points that fit in copy */
50
51
1.82k
        options = UTF8PROC_STRIPCC | UTF8PROC_NLF2LS | UTF8PROC_NLF2PS;
52
1.82k
        memcpy(copy, data, size * sizeof(utf8proc_int32_t));
53
1.82k
        utf8proc_normalize_utf32(copy, size, options);
54
55
1.82k
        options = UTF8PROC_STRIPCC | UTF8PROC_NLF2LS;
56
1.82k
        memcpy(copy, data, size * sizeof(utf8proc_int32_t));
57
1.82k
        utf8proc_normalize_utf32(copy, size, options);
58
59
1.82k
        options = UTF8PROC_STRIPCC | UTF8PROC_NLF2PS;
60
1.82k
        memcpy(copy, data, size * sizeof(utf8proc_int32_t));
61
1.82k
        utf8proc_normalize_utf32(copy, size, options);
62
63
1.82k
        options = UTF8PROC_STRIPCC;
64
1.82k
        memcpy(copy, data, size * sizeof(utf8proc_int32_t));
65
1.82k
        utf8proc_normalize_utf32(copy, size, options);
66
67
1.82k
        options = UTF8PROC_LUMP;
68
1.82k
        memcpy(copy, data, size * sizeof(utf8proc_int32_t));
69
1.82k
        utf8proc_normalize_utf32(copy, size, options);
70
71
1.82k
        options = 0;
72
1.82k
        memcpy(copy, data, size * sizeof(utf8proc_int32_t));
73
1.82k
        utf8proc_normalize_utf32(copy, size, options);
74
75
1.82k
        free(copy);
76
1.82k
    }
77
78
2.11k
    utf8proc_free(utf8proc_NFD(data));
79
2.11k
    utf8proc_free(utf8proc_NFC(data));
80
2.11k
    utf8proc_free(utf8proc_NFKD(data));
81
2.11k
    utf8proc_free(utf8proc_NFKC(data));
82
2.11k
    utf8proc_free(utf8proc_NFKC_Casefold(data));
83
84
2.11k
    utf8proc_map(data, len, &str, UTF8PROC_CHARBOUND | UTF8PROC_STRIPNA);
85
2.11k
    utf8proc_free(str);
86
87
2.11k
    utf8proc_map(data, len, &str, UTF8PROC_LUMP | UTF8PROC_NLF2LS | UTF8PROC_NLF2PS);
88
2.11k
    utf8proc_free(str);
89
90
2.11k
    utf8proc_map(data, len, &str, UTF8PROC_COMPOSE | UTF8PROC_STRIPMARK);
91
2.11k
    utf8proc_free(str);
92
93
2.11k
    utf8proc_map(data, len, &str, UTF8PROC_CHARBOUND | UTF8PROC_DECOMPOSE);
94
2.11k
    utf8proc_free(str);
95
96
2.11k
    utf8proc_map(data, len, &str, UTF8PROC_CHARBOUND | UTF8PROC_COMPOSE);
97
2.11k
    utf8proc_free(str);
98
99
2.11k
    return 0;
100
2.12k
}