|
1 | 1 | #include <utf8proc.h> |
| 2 | +#include <string.h> |
2 | 3 |
|
3 | 4 | int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) |
4 | 5 | { |
5 | 6 | if(size < 1) return 0; |
6 | 7 |
|
7 | 8 | if(data[size-1] != '\0') return 0; |
8 | 9 |
|
| 10 | + const uint8_t* ptr = data; |
| 11 | + utf8proc_int32_t c = 0; |
| 12 | + utf8proc_option_t options; |
| 13 | + utf8proc_ssize_t ret, bytes = 0; |
| 14 | + size_t len = strlen((const char*)data); |
| 15 | + |
| 16 | + while(bytes != len) |
| 17 | + { |
| 18 | + ret = utf8proc_iterate(ptr, -1, &c); |
| 19 | + |
| 20 | + if(ret < 0 || ret == 0) break; |
| 21 | + |
| 22 | + bytes += ret; |
| 23 | + ptr += ret; |
| 24 | + |
| 25 | + utf8proc_tolower(c); |
| 26 | + utf8proc_toupper(c); |
| 27 | + utf8proc_totitle(c); |
| 28 | + utf8proc_islower(c); |
| 29 | + utf8proc_isupper(c); |
| 30 | + utf8proc_charwidth(c); |
| 31 | + utf8proc_category(c); |
| 32 | + utf8proc_category_string(c); |
| 33 | + utf8proc_codepoint_valid(c); |
| 34 | + } |
| 35 | + |
| 36 | + utf8proc_int32_t *copy = size >= 4 ? NULL : malloc(size); |
| 37 | + |
| 38 | + if(copy) |
| 39 | + { |
| 40 | + size /= 4; |
| 41 | + |
| 42 | + options = UTF8PROC_STRIPCC | UTF8PROC_NLF2LS | UTF8PROC_NLF2PS; |
| 43 | + memcpy(copy, data, size); |
| 44 | + utf8proc_normalize_utf32(copy, size, options); |
| 45 | + |
| 46 | + options = UTF8PROC_STRIPCC | UTF8PROC_NLF2LS; |
| 47 | + memcpy(copy, data, size); |
| 48 | + utf8proc_normalize_utf32(copy, size, options); |
| 49 | + |
| 50 | + options = UTF8PROC_STRIPCC | UTF8PROC_NLF2PS; |
| 51 | + memcpy(copy, data, size); |
| 52 | + utf8proc_normalize_utf32(copy, size, options); |
| 53 | + |
| 54 | + options = UTF8PROC_STRIPCC; |
| 55 | + memcpy(copy, data, size); |
| 56 | + utf8proc_normalize_utf32(copy, size, options); |
| 57 | + |
| 58 | + options = 0; |
| 59 | + memcpy(copy, data, size); |
| 60 | + utf8proc_normalize_utf32(copy, size, options); |
| 61 | + |
| 62 | + free(copy); |
| 63 | + } |
| 64 | + |
9 | 65 | free(utf8proc_NFD(data)); |
10 | 66 | free(utf8proc_NFC(data)); |
11 | 67 | free(utf8proc_NFKD(data)); |
|
0 commit comments