• 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 #include "unicode/vtzone.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 
15   // Limit the test for at most 1000 Unicode characters.
16   if (size > 2000) {
17     size = 2000;
18   }
19   size_t unistr_size = size/2;
20   std::unique_ptr<char16_t[]> fuzzbuff(new char16_t[unistr_size]);
21   std::memcpy(fuzzbuff.get(), data, unistr_size * 2);
22   icu::UnicodeString fuzzstr(false, fuzzbuff.get(), unistr_size);
23 
24   icu::LocalPointer<icu::TimeZone> tz(
25       icu::TimeZone::createTimeZone(fuzzstr));
26 
27   icu::TimeZone::getEquivalentID(fuzzstr, size);
28 
29   icu::UnicodeString output;
30 
31   UErrorCode status = U_ZERO_ERROR;
32   UBool system;
33   icu::TimeZone::getCanonicalID(fuzzstr, output, system, status);
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 
44   tz.adoptInstead(icu::VTimeZone::createVTimeZoneByID(fuzzstr));
45 
46   status = U_ZERO_ERROR;
47   tz.adoptInstead(icu::VTimeZone::createVTimeZone(fuzzstr, status));
48   return 0;
49 }
50