|
| 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/dtptngen.h" |
| 8 | +#include "unicode/localpointer.h" |
| 9 | +#include "unicode/locid.h" |
| 10 | + |
| 11 | +IcuEnvironment* env = new IcuEnvironment(); |
| 12 | + |
| 13 | +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 14 | + UErrorCode status = U_ZERO_ERROR; |
| 15 | + |
| 16 | + uint16_t rnd16; |
| 17 | + |
| 18 | + if (size < 2 + sizeof(rnd16)) |
| 19 | + return 0; |
| 20 | + |
| 21 | + std::memcpy(&rnd16, data, sizeof(rnd16)); |
| 22 | + size -= sizeof(rnd16); |
| 23 | + data += sizeof(rnd16); |
| 24 | + const icu::Locale& locale = GetRandomLocale(rnd16); |
| 25 | + |
| 26 | + std::unique_ptr<char16_t[]> fuzzbuff(new char16_t[size/2]); |
| 27 | + std::memcpy(fuzzbuff.get(), data, (size/2)*2); |
| 28 | + icu::UnicodeString fuzzstr(false, fuzzbuff.get(), size/2); |
| 29 | + |
| 30 | + icu::LocalPointer<icu::DateTimePatternGenerator > gen( |
| 31 | + icu::DateTimePatternGenerator::createInstance(locale, status), status); |
| 32 | + if (U_FAILURE(status)) |
| 33 | + return 0; |
| 34 | + |
| 35 | + status = U_ZERO_ERROR; |
| 36 | + gen->getSkeleton(fuzzstr, status); |
| 37 | + |
| 38 | + status = U_ZERO_ERROR; |
| 39 | + gen->getBaseSkeleton(fuzzstr, status); |
| 40 | + |
| 41 | + status = U_ZERO_ERROR; |
| 42 | + gen->getBaseSkeleton(fuzzstr, status); |
| 43 | + |
| 44 | + status = U_ZERO_ERROR; |
| 45 | + gen->getPatternForSkeleton(fuzzstr); |
| 46 | + |
| 47 | + status = U_ZERO_ERROR; |
| 48 | + gen->getBestPattern(fuzzstr, status); |
| 49 | + |
| 50 | + status = U_ZERO_ERROR; |
| 51 | + icu::DateTimePatternGenerator::staticGetSkeleton(fuzzstr, status); |
| 52 | + |
| 53 | + status = U_ZERO_ERROR; |
| 54 | + icu::DateTimePatternGenerator::staticGetBaseSkeleton (fuzzstr, status); |
| 55 | + return 0; |
| 56 | +} |
0 commit comments