Commit c5698b5c authored by Jungshik Shin's avatar Jungshik Shin Committed by Commit Bot

Initialize ICU to load ICU data file for fuzzing

A couple of fuzzers that rely on url/ didn't initialize
ICU. Because url/ depends on ICU for IDN handling, this
results in an assertion failure when ICU's IDN class is
initialized.

Initialize ICU in a test enivornment for the following fuzzers:
  payment_method_manifest_parser_fuzzer
  csv_reader_fuzzer

In addition, print a human readable error message instead of a numeric
error code.

Bug: 754996
Test: The two fuzzers above do not fail the assertion about UIDNA.
Change-Id: I942d339d1ef1d71dd5c9c4e79a774f2c2980555d
Reviewed-on: https://chromium-review.googlesource.com/871350Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarJay Civelli <jcivelli@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarAbhishek Arya <inferno@chromium.org>
Commit-Queue: Abhishek Arya <inferno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532894}
parent 3955573a
......@@ -175,7 +175,6 @@ static_library("browser") {
deps = [
":hash_password_manager",
":proto",
"//base",
"//base:i18n",
"//components/autofill/core/browser",
"//components/autofill/core/browser/proto",
......@@ -426,6 +425,7 @@ fuzzer_test("csv_reader_fuzzer") {
]
deps = [
":browser",
"//base:i18n",
"//components/autofill/core/common:common",
]
seed_corpus = "import/password_csv_reader_corpus"
......
......@@ -8,11 +8,21 @@
#include <string>
#include <vector>
#include "base/at_exit.h"
#include "base/i18n/icu_util.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/import/password_csv_reader.h"
namespace password_manager {
struct IcuEnvironment {
IcuEnvironment() { CHECK(base::i18n::InitializeICU()); }
// used by ICU integration.
base::AtExitManager at_exit_manager;
};
IcuEnvironment* env = new IcuEnvironment();
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
std::vector<autofill::PasswordForm> passwords;
PasswordCSVReader reader;
......
......@@ -42,6 +42,7 @@ fuzzer_test("payment_method_manifest_fuzzer") {
deps = [
":utility",
"//base",
"//base:i18n",
"//url",
]
dict = "payment_manifest_json.dict"
......
......@@ -7,17 +7,24 @@
#include <string>
#include <vector>
#include "base/at_exit.h"
#include "base/i18n/icu_util.h"
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "components/payments/content/utility/payment_manifest_parser.h"
#include "url/gurl.h"
#include "url/origin.h"
struct Environment {
Environment() { logging::SetMinLogLevel(logging::LOG_FATAL); }
struct IcuEnvironment {
IcuEnvironment() {
logging::SetMinLogLevel(logging::LOG_FATAL);
CHECK(base::i18n::InitializeICU());
}
// used by ICU integration.
base::AtExitManager at_exit_manager;
};
Environment* env = new Environment();
IcuEnvironment* env = new IcuEnvironment();
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
std::vector<GURL> web_app_manifest_urls;
......
......@@ -13,6 +13,7 @@
#include "third_party/icu/source/common/unicode/ucnv.h"
#include "third_party/icu/source/common/unicode/ucnv_cb.h"
#include "third_party/icu/source/common/unicode/uidna.h"
#include "third_party/icu/source/common/unicode/utypes.h"
#include "url/url_canon_icu.h"
#include "url/url_canon_internal.h" // for _itoa_s
......@@ -101,7 +102,8 @@ struct UIDNAWrapper {
// registrars, search engines) converge toward a consensus.
value = uidna_openUTS46(UIDNA_CHECK_BIDI, &err);
if (U_FAILURE(err)) {
CHECK(false) << "failed to open UTS46 data with error: " << err
CHECK(false) << "failed to open UTS46 data with error: "
<< u_errorName(err)
<< ". If you see this error message in a test environment "
<< "your test environment likely lacks the required data "
<< "tables for libicu. See https://crbug.com/778929.";
......
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