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

Side by Side Diff: test/fuzzer/regexp.cc

Issue 1655853002: [regexp] add fuzzer support for regexp parser and compiler. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix fuzzer.gyp Created 4 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 unified diff | Download patch
« no previous file with comments | « test/fuzzer/fuzzer.isolate ('k') | test/fuzzer/regexp/test00 » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project 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
5 #include <stddef.h>
6 #include <stdint.h>
7
8 #include "include/v8.h"
9 #include "src/factory.h"
10 #include "src/objects-inl.h"
11 #include "src/objects.h"
12 #include "src/regexp/jsregexp.h"
13 #include "test/fuzzer/fuzzer-support.h"
14
15 namespace i = v8::internal;
16
17 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
18 v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get();
19 v8::Isolate* isolate = support->GetIsolate();
20
21 v8::Isolate::Scope isolate_scope(isolate);
22 v8::HandleScope handle_scope(isolate);
23 v8::Context::Scope context_scope(support->GetContext());
24 v8::TryCatch try_catch(isolate);
25
26 i::FLAG_harmony_unicode_regexps = true;
27 i::FLAG_harmony_regexp_lookbehind = true;
28
29 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
30 i::Factory* factory = i_isolate->factory();
31
32 if (size > INT_MAX) return 0;
33 i::MaybeHandle<i::String> maybe_source = factory->NewStringFromOneByte(
34 i::Vector<const uint8_t>(data, static_cast<int>(size)));
35 i::Handle<i::String> source;
36 if (!maybe_source.ToHandle(&source)) return 0;
37
38 static const int kAllFlags = i::JSRegExp::kGlobal | i::JSRegExp::kIgnoreCase |
39 i::JSRegExp::kMultiline | i::JSRegExp::kSticky |
40 i::JSRegExp::kUnicode;
41
42 const uint8_t one_byte_array[6] = {'f', 'o', 'o', 'b', 'a', 'r'};
43 const i::uc16 two_byte_array[6] = {'f', 0xD83D, 0xDCA9, 'b', 'a', 0x2603};
44
45 i::Handle<i::JSArray> results_array = factory->NewJSArray(4);
46 i::Handle<i::String> one_byte =
47 factory->NewStringFromOneByte(i::Vector<const uint8_t>(one_byte_array, 6))
48 .ToHandleChecked();
49 i::Handle<i::String> two_byte =
50 factory->NewStringFromTwoByte(i::Vector<const i::uc16>(two_byte_array, 6))
51 .ToHandleChecked();
52
53 for (int flags = 0; flags <= kAllFlags; flags++) {
54 v8::TryCatch try_catch(isolate);
55 i::MaybeHandle<i::JSRegExp> maybe_regexp =
56 i::JSRegExp::New(source, static_cast<i::JSRegExp::Flags>(flags));
57 i::Handle<i::JSRegExp> regexp;
58 if (!maybe_regexp.ToHandle(&regexp)) continue;
59 USE(i::RegExpImpl::Exec(regexp, one_byte, 0, results_array).is_null() &&
60 i::RegExpImpl::Exec(regexp, two_byte, 0, results_array).is_null());
61 }
62
63 return 0;
64 }
OLDNEW
« no previous file with comments | « test/fuzzer/fuzzer.isolate ('k') | test/fuzzer/regexp/test00 » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698