diff --git a/.gitignore b/.gitignore index df007078aab..a335d3c5b1b 100644 --- a/.gitignore +++ b/.gitignore @@ -427,6 +427,9 @@ icu4c/source/test/cintltst/release icu4c/source/test/cintltst/x64 icu4c/source/test/cintltst/x86 icu4c/source/test/compat/Makefile +icu4c/source/test/fuzzer/Makefile +icu4c/source/test/fuzzer/*.d +icu4c/source/test/fuzzer/*.o icu4c/source/test/hdrtst/Makefile icu4c/source/test/hdrtst/ht_* icu4c/source/test/intltest/*.d diff --git a/icu4c/source/test/fuzzer/Makefile.in b/icu4c/source/test/fuzzer/Makefile.in index f56b78de9ad..37c609dfc89 100644 --- a/icu4c/source/test/fuzzer/Makefile.in +++ b/icu4c/source/test/fuzzer/Makefile.in @@ -33,7 +33,7 @@ CPPFLAGS += -I$(srcdir) -I$(top_srcdir)/common -I$(top_srcdir)/i18n -I$(top_srcd DEFS += -D'U_TOPSRCDIR="$(top_srcdir)/"' -D'U_TOPBUILDDIR="$(BUILDDIR)"' LIBS = $(LIBCTESTFW) $(LIBICUTOOLUTIL) $(LIBICUIO) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M) -FUZZER_TARGETS = break_iterator_fuzzer collator_compare_fuzzer converter_fuzzer locale_fuzzer number_format_fuzzer ucasemap_fuzzer uloc_canonicalize_fuzzer uloc_for_language_tag_fuzzer uloc_get_name_fuzzer uloc_is_right_to_left_fuzzer uloc_open_keywords_fuzzer unicode_string_codepage_create_fuzzer uregex_open_fuzzer +FUZZER_TARGETS = break_iterator_fuzzer collator_compare_fuzzer collator_rulebased_fuzzer converter_fuzzer locale_fuzzer number_format_fuzzer ucasemap_fuzzer uloc_canonicalize_fuzzer uloc_for_language_tag_fuzzer uloc_get_name_fuzzer uloc_is_right_to_left_fuzzer uloc_open_keywords_fuzzer unicode_string_codepage_create_fuzzer uregex_open_fuzzer OBJECTS = $(FUZZER_TARGETS:%=%.o) OBJECTS += fuzzer_driver.o locale_util.o diff --git a/icu4c/source/test/fuzzer/collator_compare_fuzzer.cpp b/icu4c/source/test/fuzzer/collator_compare_fuzzer.cpp new file mode 100644 index 00000000000..b42b124e71e --- /dev/null +++ b/icu4c/source/test/fuzzer/collator_compare_fuzzer.cpp @@ -0,0 +1,35 @@ +// © 2019 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html + +#include + +#include "fuzzer_utils.h" +#include "unicode/coll.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; + + if (size < 2) + return 0; + + std::unique_ptr compbuff1(new char16_t[size/4]); + std::memcpy(compbuff1.get(), data, size/2); + data = data + size/2; + std::unique_ptr compbuff2(new char16_t[size/4]); + std::memcpy(compbuff2.get(), data, size/2); + + icu::LocalPointer fuzzCollator( + icu::Collator::createInstance(icu::Locale::getUS(), status), status); + if (U_FAILURE(status)) + return 0; + fuzzCollator->setStrength(icu::Collator::TERTIARY); + + fuzzCollator->compare(compbuff1.get(), size/4, + compbuff2.get(), size/4); + + return 0; +} diff --git a/icu4c/source/test/fuzzer/collator_rulebased_fuzzer.cpp b/icu4c/source/test/fuzzer/collator_rulebased_fuzzer.cpp new file mode 100644 index 00000000000..98785000acb --- /dev/null +++ b/icu4c/source/test/fuzzer/collator_rulebased_fuzzer.cpp @@ -0,0 +1,26 @@ +// © 2019 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html + +#include + +#include "fuzzer_utils.h" +#include "unicode/coll.h" +#include "unicode/localpointer.h" +#include "unicode/locid.h" +#include "unicode/tblcoll.h" + +IcuEnvironment* env = new IcuEnvironment(); + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + UErrorCode status = U_ZERO_ERROR; + + size_t unistr_size = size/2; + std::unique_ptr fuzzbuff(new char16_t[unistr_size]); + std::memcpy(fuzzbuff.get(), data, unistr_size * 2); + icu::UnicodeString fuzzstr(false, fuzzbuff.get(), unistr_size); + + icu::LocalPointer col1( + new icu::RuleBasedCollator(fuzzstr, status)); + + return 0; +} diff --git a/icu4c/source/test/fuzzer/collator_rulebased_fuzzer_seed_corpus.txt b/icu4c/source/test/fuzzer/collator_rulebased_fuzzer_seed_corpus.txt new file mode 100644 index 00000000000..241b803795a Binary files /dev/null and b/icu4c/source/test/fuzzer/collator_rulebased_fuzzer_seed_corpus.txt differ