• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)13 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
14     UProperty prop;
15     UChar32 c32;
16 
17     if (size < sizeof(prop) + sizeof(c32)) return 0;
18 
19     icu::StringPiece fuzzData(reinterpret_cast<const char *>(data), size);
20 
21     std::memcpy(&prop, fuzzData.data(), sizeof(prop));
22     fuzzData.remove_prefix(sizeof(prop));
23 
24     std::memcpy(&c32, fuzzData.data(), sizeof(c32));
25     fuzzData.remove_prefix(sizeof(c32));
26 
27     u_hasBinaryProperty(c32, prop);
28 
29     UErrorCode status = U_ZERO_ERROR;
30     u_getBinaryPropertySet(prop, &status);
31 
32     u_getIntPropertyValue(c32, prop);
33     u_getIntPropertyMinValue(prop);
34     u_getIntPropertyMaxValue(prop);
35 
36     status = U_ZERO_ERROR;
37     u_getIntPropertyMap(prop, &status);
38 
39     size_t unistr_size = fuzzData.length()/2;
40     const UChar* p = (const UChar*)(fuzzData.data());
41     u_stringHasBinaryProperty(p, unistr_size, prop);
42 
43     return 0;
44 }
45