Coverage Report

Created: 2026-05-16 06:30

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