/src/icu/icu4c/source/test/fuzzer/uprop_fuzzer.cpp
Line | Count | Source |
1 | | // © 2023 and later: Unicode, Inc. and others. |
2 | | // License & terms of use: http://www.unicode.org/copyright.html |
3 | | |
4 | | // Fuzzer for ICU Unicode Property. |
5 | | |
6 | | #include <cstring> |
7 | | |
8 | | #include "fuzzer_utils.h" |
9 | | |
10 | | #include "unicode/uchar.h" |
11 | | #include "unicode/locid.h" |
12 | | |
13 | 10.2k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
14 | 10.2k | UProperty prop; |
15 | 10.2k | UChar32 c32; |
16 | | |
17 | 10.2k | if (size < sizeof(prop) + sizeof(c32)) return 0; |
18 | | |
19 | 10.2k | icu::StringPiece fuzzData(reinterpret_cast<const char *>(data), size); |
20 | | |
21 | 10.2k | std::memcpy(&prop, fuzzData.data(), sizeof(prop)); |
22 | 10.2k | fuzzData.remove_prefix(sizeof(prop)); |
23 | | |
24 | 10.2k | std::memcpy(&c32, fuzzData.data(), sizeof(c32)); |
25 | 10.2k | fuzzData.remove_prefix(sizeof(c32)); |
26 | | |
27 | 10.2k | u_hasBinaryProperty(c32, prop); |
28 | | |
29 | 10.2k | UErrorCode status = U_ZERO_ERROR; |
30 | 10.2k | u_getBinaryPropertySet(prop, &status); |
31 | | |
32 | 10.2k | u_getIntPropertyValue(c32, prop); |
33 | 10.2k | u_getIntPropertyMinValue(prop); |
34 | 10.2k | u_getIntPropertyMaxValue(prop); |
35 | | |
36 | 10.2k | status = U_ZERO_ERROR; |
37 | 10.2k | u_getIntPropertyMap(prop, &status); |
38 | | |
39 | 10.2k | size_t unistr_size = fuzzData.length()/2; |
40 | 10.2k | const UChar* p = (const UChar*)(fuzzData.data()); |
41 | 10.2k | u_stringHasBinaryProperty(p, unistr_size, prop); |
42 | | |
43 | 10.2k | return 0; |
44 | 10.2k | } |