Commit 6792b39a authored by Austin Tankiang's avatar Austin Tankiang Committed by Commit Bot

Add fuzz target for address_formatter in libaddressinput

Bug: 1009109
Change-Id: If20f8bd11e5eadd7d436be0eb0bd272477ee99f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1866099Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Austin Tankiang <austinct@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707663}
parent 1bd1b58e
...@@ -308,3 +308,13 @@ fuzzer_test("libaddressinput_parse_format_rule_fuzzer") { ...@@ -308,3 +308,13 @@ fuzzer_test("libaddressinput_parse_format_rule_fuzzer") {
] ]
dict = "//third_party/libaddressinput/fuzz/data/fmt.dict" dict = "//third_party/libaddressinput/fuzz/data/fmt.dict"
} }
fuzzer_test("libaddressinput_address_formatter_fuzzer") {
sources = [
"fuzz/address_formatter_fuzzer.cc",
]
deps = [
":libaddressinput",
":util",
]
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdint.h>
#include <string>
#include <fuzzer/FuzzedDataProvider.h>
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_formatter.h"
namespace {
constexpr size_t kMaxFieldLength = 128;
} // namespace
// Entry point for LibFuzzer.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
FuzzedDataProvider provider(data, size);
i18n::addressinput::AddressData address;
address.region_code = provider.ConsumeRandomLengthString(kMaxFieldLength);
address.administrative_area =
provider.ConsumeRandomLengthString(kMaxFieldLength);
address.locality = provider.ConsumeRandomLengthString(kMaxFieldLength);
address.dependent_locality =
provider.ConsumeRandomLengthString(kMaxFieldLength);
address.postal_code = provider.ConsumeRandomLengthString(kMaxFieldLength);
address.sorting_code = provider.ConsumeRandomLengthString(kMaxFieldLength);
address.language_code = provider.ConsumeRandomLengthString(kMaxFieldLength);
address.organization = provider.ConsumeRandomLengthString(kMaxFieldLength);
address.recipient = provider.ConsumeRandomLengthString(kMaxFieldLength);
while (provider.remaining_bytes() > 0) {
address.address_line.push_back(
provider.ConsumeRandomLengthString(kMaxFieldLength));
}
std::vector<std::string> output_multiline;
i18n::addressinput::GetFormattedNationalAddress(address, &output_multiline);
std::string output;
i18n::addressinput::GetFormattedNationalAddressLine(address, &output);
i18n::addressinput::GetStreetAddressLinesAsSingleLine(address, &output);
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment