Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Unified Diff: testing/libfuzzer/fuzzers/re2_fuzzer.cc

Issue 2698653002: Use re2_fuzzer stored in re2 repository, remove old version. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « testing/libfuzzer/fuzzers/BUILD.gn ('k') | third_party/re2/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing/libfuzzer/fuzzers/re2_fuzzer.cc
diff --git a/testing/libfuzzer/fuzzers/re2_fuzzer.cc b/testing/libfuzzer/fuzzers/re2_fuzzer.cc
deleted file mode 100644
index 023a9ab8d7e74d527a9f5b436152eaebadfe895a..0000000000000000000000000000000000000000
--- a/testing/libfuzzer/fuzzers/re2_fuzzer.cc
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright 2016 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.
-
-// Copyright 2016 The RE2 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 <stddef.h>
-#include <stdint.h>
-
-#include <map>
-#include <string>
-
-#include "re2/re2.h"
-
-using re2::StringPiece;
-using std::string;
-
-// NOT static, NOT signed.
-uint8_t dummy = 0;
-
-void Test(StringPiece pattern, const RE2::Options& options, StringPiece text) {
- RE2 re(pattern, options);
- if (!re.ok())
- return;
-
- // Don't waste time fuzzing high-fanout programs.
- // (They can also cause bug reports due to fuzzer timeouts.)
- std::map<int, int> histogram;
- int fanout = re.ProgramFanout(&histogram);
- if (fanout > 9)
- return;
-
- StringPiece sp1, sp2, sp3, sp4;
- string s1, s2, s3, s4;
- int i1, i2, i3, i4;
- double d1, d2, d3, d4;
-
- RE2::FullMatch(text, re, &sp1, &sp2, &sp3, &sp4);
- RE2::PartialMatch(text, re, &s1, &s2, &s3, &s4);
-
- sp1 = sp2 = text;
- RE2::Consume(&sp1, re, &i1, &i2, &i3, &i4);
- RE2::FindAndConsume(&sp2, re, &d1, &d2, &d3, &d4);
-
- s3 = s4 = text.ToString();
- RE2::Replace(&s3, re, "");
- RE2::GlobalReplace(&s4, re, "");
-
- // Exercise some other API functionality.
- dummy += re.NumberOfCapturingGroups();
- dummy += RE2::QuoteMeta(pattern).size();
-}
-
-// Entry point for libFuzzer.
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- if (size == 0 || size > 1024)
- return 0;
-
- // The one-at-a-time hash by Bob Jenkins.
- uint32_t hash = 0;
- for (size_t i = 0; i < size; i++) {
- hash += data[i];
- hash += (hash << 10);
- hash ^= (hash >> 6);
- }
- hash += (hash << 3);
- hash ^= (hash >> 11);
- hash += (hash << 15);
-
- RE2::Options options;
- options.set_log_errors(false);
- options.set_encoding(hash & 1 ? RE2::Options::EncodingLatin1
- : RE2::Options::EncodingUTF8);
- options.set_posix_syntax(hash & 2);
- options.set_longest_match(hash & 4);
- options.set_literal(hash & 8);
- options.set_never_nl(hash & 16);
- options.set_dot_nl(hash & 32);
- options.set_never_capture(hash & 64);
- options.set_case_sensitive(hash & 128);
- options.set_perl_classes(hash & 256);
- options.set_word_boundary(hash & 512);
- options.set_one_line(hash & 1024);
-
- const char* ptr = reinterpret_cast<const char*>(data);
- int len = static_cast<int>(size);
-
- StringPiece pattern(ptr, len);
- StringPiece text(ptr, len);
- Test(pattern, options, text);
-
- for (int i = 2; i <= 4; i++) {
- if (len < i)
- break;
-
- int frac = len / i;
- pattern = StringPiece(ptr, frac);
- text = StringPiece(ptr + frac, len - frac);
- Test(pattern, options, text);
- }
-
- return 0;
-}
« no previous file with comments | « testing/libfuzzer/fuzzers/BUILD.gn ('k') | third_party/re2/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698