• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <fuzzer/FuzzedDataProvider.h>
6 #include <stdint.h>
7 
8 #include <string>
9 #include <tuple>
10 
11 #include "base/strings/sys_string_conversions.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "build/build_config.h"
14 
15 namespace base {
16 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)17 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
18   FuzzedDataProvider provider(data, size);
19   const std::string text = provider.ConsumeRandomLengthString();
20   const std::wstring wide_text = UTF8ToWide(text);
21 
22   std::ignore = SysWideToUTF8(wide_text);
23   std::ignore = SysUTF8ToWide(text);
24   std::ignore = SysWideToNativeMB(wide_text);
25   std::ignore = SysNativeMBToWide(text);
26 
27 #if BUILDFLAG(IS_WIN)
28   const uint32_t code_page = provider.ConsumeIntegral<uint32_t>();
29   std::ignore = SysMultiByteToWide(text, code_page);
30   std::ignore = SysWideToMultiByte(wide_text, code_page);
31 #endif
32 
33   return 0;
34 }
35 
36 }  // namespace base
37