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