1 // © 2019 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3
4 #include <cstring>
5
6 #include "fuzzer_utils.h"
7 #include "unicode/coll.h"
8 #include "unicode/localpointer.h"
9 #include "unicode/locid.h"
10
11 IcuEnvironment* env = new IcuEnvironment();
12
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)13 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
14 UErrorCode status = U_ZERO_ERROR;
15
16 if (size < 2)
17 return 0;
18
19 std::unique_ptr<char16_t> compbuff1(new char16_t[size/4]);
20 std::memcpy(compbuff1.get(), data, (size/4)*2);
21 data = data + size/2;
22 std::unique_ptr<char16_t> compbuff2(new char16_t[size/4]);
23 std::memcpy(compbuff2.get(), data, (size/4)*2);
24
25 icu::LocalPointer<icu::Collator> fuzzCollator(
26 icu::Collator::createInstance(icu::Locale::getUS(), status), status);
27 if (U_FAILURE(status))
28 return 0;
29 fuzzCollator->setStrength(icu::Collator::TERTIARY);
30
31 fuzzCollator->compare(compbuff1.get(), size/4,
32 compbuff2.get(), size/4);
33
34 return 0;
35 }
36