Commit 0a6007aa authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

Create fuzzer for the compact encoding detection library.

BUG=None

Change-Id: If9ca23541732251aa800c0335c8b094235e631a7
Reviewed-on: https://chromium-review.googlesource.com/c/1343458
Commit-Queue: Abhishek Arya <inferno@chromium.org>
Reviewed-by: default avatarAbhishek Arya <inferno@chromium.org>
Reviewed-by: default avatarJungshik Shin <jshin@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609707}
parent 6013fa2b
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# found in the LICENSE file. # found in the LICENSE file.
import("//testing/test.gni") import("//testing/test.gni")
import("//testing/libfuzzer/fuzzer_test.gni")
config("ced_config") { config("ced_config") {
include_dirs = [ "src" ] include_dirs = [ "src" ]
...@@ -96,3 +97,13 @@ test("ced_unittests") { ...@@ -96,3 +97,13 @@ test("ced_unittests") {
"//testing/gtest:gtest_main", "//testing/gtest:gtest_main",
] ]
} }
fuzzer_test("compact_enc_det_fuzzer") {
sources = [
"compact_enc_det_fuzzer.cc",
]
deps = [
":ced",
"//base/test:test_support",
]
}
specific_include_rules = {
'compact_enc_det_fuzzer\.cc': [
'+base/test/fuzzed_data_provider.h',
],
}
// Copyright 2018 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 <string>
#include "base/test/fuzzed_data_provider.h"
#include "third_party/ced/src/compact_enc_det/compact_enc_det.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
base::FuzzedDataProvider data_provider(data, size);
CompactEncDet::TextCorpusType corpus =
static_cast<CompactEncDet::TextCorpusType>(
data_provider.ConsumeInt32InRange(0, CompactEncDet::NUM_CORPA));
Encoding encoding_hint = static_cast<Encoding>(
data_provider.ConsumeInt32InRange(0, NUM_ENCODINGS));
Language langauge_hint = static_cast<Language>(
data_provider.ConsumeInt32InRange(0, NUM_LANGUAGES));
bool ignore_7bit_mail_encodings = data_provider.ConsumeBool();
std::string text = data_provider.ConsumeRemainingBytes();
int bytes_consumed = 0;
bool is_reliable = false;
CompactEncDet::DetectEncoding(
text.c_str(), text.length(), nullptr /* url_hint */,
nullptr /* http_charset_hint */, nullptr /* meta_charset_hint */,
encoding_hint, langauge_hint, corpus, ignore_7bit_mail_encodings,
&bytes_consumed, &is_reliable);
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