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