]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/fuzzer/converter_fuzzer.cpp
1 // © 2019 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
14 #include "fuzzer_utils.h"
15 #include "unicode/unistr.h"
16 #include "unicode/ucnv.h"
18 IcuEnvironment
* env
= new IcuEnvironment();
21 using deleted_unique_ptr
= std::unique_ptr
<T
, std::function
<void(T
*)>>;
23 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data
, size_t size
) {
24 UErrorCode status
= U_ZERO_ERROR
;
31 rnd
= *(reinterpret_cast<const uint16_t *>(data
));
35 size_t unistr_size
= size
/2;
36 std::unique_ptr
<char16_t[]> fuzzbuff(new char16_t[unistr_size
]);
37 std::memcpy(fuzzbuff
.get(), data
, unistr_size
* 2);
39 icu::UnicodeString
fuzzstr(false, fuzzbuff
.get(), unistr_size
);
41 const char* converter_name
=
42 ucnv_getAvailableName(rnd
% ucnv_countAvailable());
43 deleted_unique_ptr
<UConverter
> converter(ucnv_open(converter_name
, &status
),
45 if (U_FAILURE(status
)) {
49 static const size_t dest_buffer_size
= 1024 * 1204;
50 static const std::unique_ptr
<char[]> dest_buffer(new char[dest_buffer_size
]);
52 fuzzstr
.extract(dest_buffer
.get(), dest_buffer_size
, converter
.get(), status
);