• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2024 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 
4 #include <cstring>
5 #include <stddef.h>
6 #include <stdint.h>
7 #include <string.h>
8 
9 
10 #include "fuzzer_utils.h"
11 #include "unicode/messageformat2.h"
12 #include "unicode/messagepattern.h"
13 #include "unicode/msgfmt.h"
14 
15 IcuEnvironment* env = new IcuEnvironment();
16 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)17 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
18   UParseError pe = { 0, 0, {0}, {0} };
19   UErrorCode status = U_ZERO_ERROR;
20 
21   size_t unistr_size = size/2;
22   std::unique_ptr<char16_t[]> fuzzbuff(new char16_t[unistr_size]);
23   std::memcpy(fuzzbuff.get(), data, unistr_size * 2);
24   icu::UnicodeString fuzzstr(false, fuzzbuff.get(), unistr_size);
25 
26   icu::MessageFormat mfmt(fuzzstr, status);
27 
28   status = U_ZERO_ERROR;
29   icu::MessagePattern mpat(fuzzstr, &pe, status);
30   pe = { 0, 0, {0}, {0} };
31 
32   status = U_ZERO_ERROR;
33   icu::message2::MessageFormatter msgfmt2 =
34       icu::message2::MessageFormatter::Builder(status)
35       .setPattern(fuzzstr, pe, status)
36       .build(status);
37   return 0;
38 }
39