]>
Commit | Line | Data |
---|---|---|
3d1f044b A |
1 | // © 2019 and later: Unicode, Inc. and others. |
2 | // License & terms of use: http://www.unicode.org/copyright.html | |
3 | ||
4 | // Fuzzer for NumberFormat::parse. | |
5 | ||
6 | #include <stddef.h> | |
7 | #include <stdint.h> | |
8 | #include <memory> | |
9 | #include "fuzzer_utils.h" | |
10 | #include "unicode/numfmt.h" | |
11 | ||
12 | IcuEnvironment* env = new IcuEnvironment(); | |
13 | ||
14 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | |
15 | UErrorCode status = U_ZERO_ERROR; | |
16 | uint16_t rnd = 0; | |
17 | ||
18 | if (size < 2) { | |
19 | return 0; | |
20 | } | |
21 | ||
22 | rnd = *(reinterpret_cast<const uint16_t *>(data)); | |
23 | data = data + 2; | |
24 | size = size - 2; | |
25 | ||
26 | size_t unistr_size = size/2; | |
27 | std::unique_ptr<char16_t[]> fuzzbuff(new char16_t[unistr_size]); | |
28 | std::memcpy(fuzzbuff.get(), data, unistr_size * 2); | |
29 | ||
30 | const icu::Locale& locale = GetRandomLocale(rnd); | |
31 | ||
32 | std::unique_ptr<icu::NumberFormat> fmt( | |
33 | icu::NumberFormat::createInstance(locale, status)); | |
34 | if (U_FAILURE(status)) { | |
35 | return 0; | |
36 | } | |
37 | ||
38 | icu::UnicodeString fuzzstr(false, fuzzbuff.get(), unistr_size); | |
39 | icu::Formattable result; | |
40 | fmt->parse(fuzzstr, result, status); | |
41 | ||
42 | return 0; | |
43 | } |