Skip to content

Commit

Permalink
ICU-22549 Revert "Improve fuzzer to test more locale"
Browse files Browse the repository at this point in the history
See #2770
  • Loading branch information
FrankYFTang committed Jan 3, 2024
1 parent 1a60a03 commit 52ff51e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 54 deletions.
20 changes: 0 additions & 20 deletions icu4c/source/test/fuzzer/break_iterator_fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
for (int32_t p = bi->first(); p != icu::BreakIterator::DONE; p = bi->next()) {}

utext_close(fuzzstr);

icu::Locale locale2(reinterpret_cast<const char*>(data));
switch (rnd8 % 5) {
case 0:
bi.reset(icu::BreakIterator::createWordInstance(locale2, status));
break;
case 1:
bi.reset(icu::BreakIterator::createLineInstance(locale2, status));
break;
case 2:
bi.reset(icu::BreakIterator::createCharacterInstance(locale2, status));
break;
case 3:
bi.reset(icu::BreakIterator::createSentenceInstance(locale2, status));
break;
case 4:
bi.reset(icu::BreakIterator::createTitleInstance(locale2, status));
break;
}

return 0;
}

17 changes: 7 additions & 10 deletions icu4c/source/test/fuzzer/collator_compare_fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,22 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (size > 4096) {
size = 4096;
}
std::unique_ptr<char16_t[]> compbuff1(new char16_t[size/4]);
std::unique_ptr<char16_t> compbuff1(new char16_t[size/4]);
std::memcpy(compbuff1.get(), data, (size/4)*2);
data = data + size/2;
std::unique_ptr<char16_t[]> compbuff2(new char16_t[size/4]);
std::unique_ptr<char16_t> compbuff2(new char16_t[size/4]);
std::memcpy(compbuff2.get(), data, (size/4)*2);


icu::LocalPointer<icu::Collator> fuzzCollator(
icu::Collator::createInstance(locale, status), status);
if (U_SUCCESS(status)) {
if (U_FAILURE(status))
return 0;

fuzzCollator->setStrength(strength);
fuzzCollator->setStrength(strength);

fuzzCollator->compare(compbuff1.get(), size/4,
compbuff2.get(), size/4);
}
status = U_ZERO_ERROR;
fuzzCollator->compare(compbuff1.get(), size/4,
compbuff2.get(), size/4);

fuzzCollator.adoptInstead(
icu::Collator::createInstance(icu::Locale(reinterpret_cast<const char*>(data)), status));
return 0;
}
6 changes: 0 additions & 6 deletions icu4c/source/test/fuzzer/date_format_fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,5 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (U_SUCCESS(status)) {
df->format(date, appendTo);
}

icu::Locale locale2(fuzzData.data());
df.reset(
icu::DateFormat::createDateTimeInstance(dateStyle, timeStyle, locale2));
df.reset(
icu::DateFormat::createDateTimeInstance(dateStyle2, timeStyle2, locale2));
return EXIT_SUCCESS;
}
33 changes: 15 additions & 18 deletions icu4c/source/test/fuzzer/date_time_pattern_generator_fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,28 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {

icu::LocalPointer<icu::DateTimePatternGenerator > gen(
icu::DateTimePatternGenerator::createInstance(locale, status), status);
if (U_SUCCESS(status)) {

status = U_ZERO_ERROR;
gen->getSkeleton(fuzzstr, status);
if (U_FAILURE(status))
return 0;

status = U_ZERO_ERROR;
gen->getBaseSkeleton(fuzzstr, status);
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->getBaseSkeleton(fuzzstr, status);

status = U_ZERO_ERROR;
gen->getBestPattern(fuzzstr, status);
status = U_ZERO_ERROR;
gen->getPatternForSkeleton(fuzzstr);

status = U_ZERO_ERROR;
icu::DateTimePatternGenerator::staticGetSkeleton(fuzzstr, status);
status = U_ZERO_ERROR;
gen->getBestPattern(fuzzstr, status);

status = U_ZERO_ERROR;
icu::DateTimePatternGenerator::staticGetBaseSkeleton (fuzzstr, status);
}
status = U_ZERO_ERROR;
icu::DateTimePatternGenerator::staticGetSkeleton(fuzzstr, status);

status = U_ZERO_ERROR;
gen.adoptInstead(icu::DateTimePatternGenerator::createInstance(icu::Locale(reinterpret_cast<const char*>(data)), status));
icu::DateTimePatternGenerator::staticGetBaseSkeleton (fuzzstr, status);
return 0;
}

0 comments on commit 52ff51e

Please sign in to comment.