forked from unicode-org/icu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ICU-22549 Add DateTimePatternGenerator fuzzer
See unicode-org#2708
- Loading branch information
1 parent
57877d6
commit a4b4aa1
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
icu4c/source/test/fuzzer/date_time_pattern_generator_fuzzer.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// © 2019 and later: Unicode, Inc. and others. | ||
// License & terms of use: http://www.unicode.org/copyright.html | ||
|
||
#include <cstring> | ||
|
||
#include "fuzzer_utils.h" | ||
#include "unicode/dtptngen.h" | ||
#include "unicode/localpointer.h" | ||
#include "unicode/locid.h" | ||
|
||
IcuEnvironment* env = new IcuEnvironment(); | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | ||
UErrorCode status = U_ZERO_ERROR; | ||
|
||
uint16_t rnd16; | ||
|
||
if (size < 2 + sizeof(rnd16)) | ||
return 0; | ||
|
||
std::memcpy(&rnd16, data, sizeof(rnd16)); | ||
size -= sizeof(rnd16); | ||
data += sizeof(rnd16); | ||
const icu::Locale& locale = GetRandomLocale(rnd16); | ||
|
||
std::unique_ptr<char16_t[]> fuzzbuff(new char16_t[size/2]); | ||
std::memcpy(fuzzbuff.get(), data, (size/2)*2); | ||
icu::UnicodeString fuzzstr(false, fuzzbuff.get(), size/2); | ||
|
||
icu::LocalPointer<icu::DateTimePatternGenerator > gen( | ||
icu::DateTimePatternGenerator::createInstance(locale, status), status); | ||
if (U_FAILURE(status)) | ||
return 0; | ||
|
||
status = U_ZERO_ERROR; | ||
gen->getSkeleton(fuzzstr, status); | ||
|
||
status = U_ZERO_ERROR; | ||
gen->getBaseSkeleton(fuzzstr, status); | ||
|
||
status = U_ZERO_ERROR; | ||
gen->getBaseSkeleton(fuzzstr, status); | ||
|
||
status = U_ZERO_ERROR; | ||
gen->getPatternForSkeleton(fuzzstr); | ||
|
||
status = U_ZERO_ERROR; | ||
gen->getBestPattern(fuzzstr, status); | ||
|
||
status = U_ZERO_ERROR; | ||
icu::DateTimePatternGenerator::staticGetSkeleton(fuzzstr, status); | ||
|
||
status = U_ZERO_ERROR; | ||
icu::DateTimePatternGenerator::staticGetBaseSkeleton (fuzzstr, status); | ||
return 0; | ||
} |