• 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 #include <cstring>
5 
6 #include "fuzzer_utils.h"
7 #include "unicode/localpointer.h"
8 #include "unicode/timezone.h"
9 
10 IcuEnvironment* env = new IcuEnvironment();
11 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)12 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
13 
14   // Limit the test for at most 1000 Unicode characters.
15   if (size > 2000) {
16     size = 2000;
17   }
18   size_t unistr_size = size/2;
19   std::unique_ptr<char16_t[]> fuzzbuff(new char16_t[unistr_size]);
20   std::memcpy(fuzzbuff.get(), data, unistr_size * 2);
21   icu::UnicodeString fuzzstr(false, fuzzbuff.get(), unistr_size);
22 
23   icu::LocalPointer<icu::TimeZone> tz(
24       icu::TimeZone::createTimeZone(fuzzstr));
25 
26   icu::TimeZone::getEquivalentID(fuzzstr, size);
27 
28   icu::UnicodeString output;
29 
30   UErrorCode status = U_ZERO_ERROR;
31   UBool system;
32   icu::TimeZone::getCanonicalID(fuzzstr, output, system, status);
33 
34 
35   status = U_ZERO_ERROR;
36   icu::TimeZone::getIanaID(fuzzstr, output, status);
37 
38   status = U_ZERO_ERROR;
39   icu::TimeZone::getWindowsID(fuzzstr, output, status);
40 
41   status = U_ZERO_ERROR;
42   icu::TimeZone::getRegion(fuzzstr, status);
43   return 0;
44 }
45