OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "include/v8.h" | 8 #include "include/v8.h" |
9 #include "src/factory.h" | 9 #include "src/factory.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
11 #include "src/objects.h" | 11 #include "src/objects.h" |
12 #include "src/regexp/jsregexp.h" | 12 #include "src/regexp/jsregexp.h" |
13 #include "test/fuzzer/fuzzer-support.h" | 13 #include "test/fuzzer/fuzzer-support.h" |
14 | 14 |
15 namespace i = v8::internal; | 15 namespace i = v8::internal; |
16 | 16 |
| 17 void Test(v8::Isolate* isolate, i::Handle<i::JSRegExp> regexp, |
| 18 i::Handle<i::String> subject, i::Handle<i::JSArray> results_array) { |
| 19 v8::TryCatch try_catch(isolate); |
| 20 USE(i::RegExpImpl::Exec(regexp, subject, 0, results_array)); |
| 21 } |
| 22 |
17 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 23 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
18 v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get(); | 24 v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get(); |
19 v8::Isolate* isolate = support->GetIsolate(); | 25 v8::Isolate* isolate = support->GetIsolate(); |
20 | 26 |
21 v8::Isolate::Scope isolate_scope(isolate); | 27 v8::Isolate::Scope isolate_scope(isolate); |
22 v8::HandleScope handle_scope(isolate); | 28 v8::HandleScope handle_scope(isolate); |
23 v8::Context::Scope context_scope(support->GetContext()); | 29 v8::Context::Scope context_scope(support->GetContext()); |
24 v8::TryCatch try_catch(isolate); | 30 v8::TryCatch try_catch(isolate); |
25 | 31 |
26 i::FLAG_harmony_unicode_regexps = true; | 32 i::FLAG_harmony_unicode_regexps = true; |
27 i::FLAG_harmony_regexp_lookbehind = true; | 33 i::FLAG_harmony_regexp_lookbehind = true; |
28 | 34 |
29 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 35 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
30 i::Factory* factory = i_isolate->factory(); | 36 i::Factory* factory = i_isolate->factory(); |
31 | 37 |
32 if (size > INT_MAX) return 0; | 38 if (size > INT_MAX) return 0; |
33 i::MaybeHandle<i::String> maybe_source = factory->NewStringFromOneByte( | 39 i::MaybeHandle<i::String> maybe_source = factory->NewStringFromOneByte( |
34 i::Vector<const uint8_t>(data, static_cast<int>(size))); | 40 i::Vector<const uint8_t>(data, static_cast<int>(size))); |
35 i::Handle<i::String> source; | 41 i::Handle<i::String> source; |
36 if (!maybe_source.ToHandle(&source)) return 0; | 42 if (!maybe_source.ToHandle(&source)) return 0; |
37 | 43 |
38 static const int kAllFlags = i::JSRegExp::kGlobal | i::JSRegExp::kIgnoreCase | | 44 static const int kAllFlags = i::JSRegExp::kGlobal | i::JSRegExp::kIgnoreCase | |
39 i::JSRegExp::kMultiline | i::JSRegExp::kSticky | | 45 i::JSRegExp::kMultiline | i::JSRegExp::kSticky | |
40 i::JSRegExp::kUnicode; | 46 i::JSRegExp::kUnicode; |
41 | 47 |
42 const uint8_t one_byte_array[6] = {'f', 'o', 'o', 'b', 'a', 'r'}; | 48 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}; | 49 const i::uc16 two_byte_array[6] = {'f', 0xD83D, 0xDCA9, 'b', 'a', 0x2603}; |
44 | 50 |
45 i::Handle<i::JSArray> results_array = factory->NewJSArray(4); | 51 i::Handle<i::JSArray> results_array = factory->NewJSArray(5); |
46 i::Handle<i::String> one_byte = | 52 i::Handle<i::String> one_byte = |
47 factory->NewStringFromOneByte(i::Vector<const uint8_t>(one_byte_array, 6)) | 53 factory->NewStringFromOneByte(i::Vector<const uint8_t>(one_byte_array, 6)) |
48 .ToHandleChecked(); | 54 .ToHandleChecked(); |
49 i::Handle<i::String> two_byte = | 55 i::Handle<i::String> two_byte = |
50 factory->NewStringFromTwoByte(i::Vector<const i::uc16>(two_byte_array, 6)) | 56 factory->NewStringFromTwoByte(i::Vector<const i::uc16>(two_byte_array, 6)) |
51 .ToHandleChecked(); | 57 .ToHandleChecked(); |
52 | 58 |
53 for (int flags = 0; flags <= kAllFlags; flags++) { | 59 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; | 60 i::Handle<i::JSRegExp> regexp; |
58 if (!maybe_regexp.ToHandle(®exp)) continue; | 61 { |
59 USE(i::RegExpImpl::Exec(regexp, one_byte, 0, results_array).is_null() && | 62 v8::TryCatch try_catch(isolate); |
60 i::RegExpImpl::Exec(regexp, two_byte, 0, results_array).is_null()); | 63 i::MaybeHandle<i::JSRegExp> maybe_regexp = |
| 64 i::JSRegExp::New(source, static_cast<i::JSRegExp::Flags>(flags)); |
| 65 if (!maybe_regexp.ToHandle(®exp)) continue; |
| 66 } |
| 67 Test(isolate, regexp, one_byte, results_array); |
| 68 Test(isolate, regexp, two_byte, results_array); |
| 69 Test(isolate, regexp, factory->empty_string(), results_array); |
| 70 Test(isolate, regexp, source, results_array); |
61 } | 71 } |
62 | 72 |
63 return 0; | 73 return 0; |
64 } | 74 } |
OLD | NEW |