• 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/uniset.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   size_t unistr_size = size/2;
17   std::unique_ptr<char16_t[]> fuzzbuff(new char16_t[unistr_size]);
18   std::memcpy(fuzzbuff.get(), data, unistr_size * 2);
19   icu::UnicodeString fuzzstr(false, fuzzbuff.get(), unistr_size);
20 
21   icu::LocalPointer<icu::UnicodeSet> set(
22       new icu::UnicodeSet(fuzzstr, status));
23 
24   status = U_ZERO_ERROR;
25 
26   set.adoptInstead(new icu::UnicodeSet());
27   set->applyPattern (fuzzstr, status);
28 
29   set.adoptInstead(new icu::UnicodeSet());
30   set->addAll(fuzzstr);
31 
32   set.adoptInstead(new icu::UnicodeSet());
33   set->add(fuzzstr);
34 
35   set.adoptInstead(new icu::UnicodeSet());
36   set->retainAll(fuzzstr);
37 
38   set.adoptInstead(new icu::UnicodeSet());
39   set->complementAll(fuzzstr);
40 
41   set.adoptInstead(new icu::UnicodeSet());
42   set->removeAll(fuzzstr);
43 
44   set.adoptInstead(new icu::UnicodeSet());
45   set->retain(fuzzstr);
46 
47   set.adoptInstead(new icu::UnicodeSet());
48   set->remove(fuzzstr);
49 
50   set.adoptInstead(new icu::UnicodeSet());
51   set->complement(fuzzstr);
52 
53   set.adoptInstead(icu::UnicodeSet::createFrom(fuzzstr));
54 
55   set.adoptInstead(icu::UnicodeSet::createFromAll(fuzzstr));
56   return 0;
57 }
58