address_formatter_fuzzer.cc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <stdint.h>
  5. #include <string>
  6. #include <fuzzer/FuzzedDataProvider.h>
  7. #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h"
  8. #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_formatter.h"
  9. namespace {
  10. constexpr size_t kMaxFieldLength = 128;
  11. } // namespace
  12. // Entry point for LibFuzzer.
  13. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  14. FuzzedDataProvider provider(data, size);
  15. i18n::addressinput::AddressData address;
  16. address.region_code = provider.ConsumeRandomLengthString(kMaxFieldLength);
  17. address.administrative_area =
  18. provider.ConsumeRandomLengthString(kMaxFieldLength);
  19. address.locality = provider.ConsumeRandomLengthString(kMaxFieldLength);
  20. address.dependent_locality =
  21. provider.ConsumeRandomLengthString(kMaxFieldLength);
  22. address.postal_code = provider.ConsumeRandomLengthString(kMaxFieldLength);
  23. address.sorting_code = provider.ConsumeRandomLengthString(kMaxFieldLength);
  24. address.language_code = provider.ConsumeRandomLengthString(kMaxFieldLength);
  25. address.organization = provider.ConsumeRandomLengthString(kMaxFieldLength);
  26. address.recipient = provider.ConsumeRandomLengthString(kMaxFieldLength);
  27. while (provider.remaining_bytes() > 0) {
  28. address.address_line.push_back(
  29. provider.ConsumeRandomLengthString(kMaxFieldLength));
  30. }
  31. std::vector<std::string> output_multiline;
  32. i18n::addressinput::GetFormattedNationalAddress(address, &output_multiline);
  33. std::string output;
  34. i18n::addressinput::GetFormattedNationalAddressLine(address, &output);
  35. i18n::addressinput::GetStreetAddressLinesAsSingleLine(address, &output);
  36. return 0;
  37. }