• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "unicode/sortkey.h"
11 #include "unicode/tblcoll.h"
12 
13 IcuEnvironment* env = new IcuEnvironment();
14 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)15 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
16   UErrorCode status = U_ZERO_ERROR;
17   if (size > 2000) {
18       // Limit the effective test data to only 2000 bytes to avoid meaningless
19       // timeout.
20       size = 2000;
21   }
22 
23   size_t unistr_size = size/2;
24   std::unique_ptr<char16_t[]> fuzzbuff(new char16_t[unistr_size]);
25   std::memcpy(fuzzbuff.get(), data, unistr_size * 2);
26   icu::UnicodeString fuzzstr(false, fuzzbuff.get(), unistr_size);
27 
28   icu::LocalPointer<icu::RuleBasedCollator> col1(
29       new icu::RuleBasedCollator(fuzzstr, status));
30 
31   if (U_SUCCESS(status)) {
32       col1->getVariableTop(status);
33       status = U_ZERO_ERROR;
34       icu::CollationKey key;
35       col1->getCollationKey(fuzzstr, key, status);
36       status = U_ZERO_ERROR;
37       icu::LocalPointer<icu::UnicodeSet> tailoredSet(col1->getTailoredSet(status));
38       status = U_ZERO_ERROR;
39       col1->getLocale(ULOC_ACTUAL_LOCALE, status);
40       status = U_ZERO_ERROR;
41       col1->getLocale(ULOC_VALID_LOCALE, status);
42       col1->getMaxVariable();
43       col1->getStrength();
44       col1->getSortKey(fuzzstr, nullptr, 0);
45   }
46   return 0;
47 }
48