2016-01-26 10:38:37 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2016-02-02 11:28:47 +00:00
|
|
|
#include <limits.h>
|
2016-01-26 10:38:37 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "include/v8.h"
|
2017-01-09 13:43:28 +00:00
|
|
|
#include "src/objects-inl.h"
|
2016-01-26 10:38:37 +00:00
|
|
|
#include "src/objects.h"
|
2016-08-22 11:33:30 +00:00
|
|
|
#include "src/parsing/parse-info.h"
|
2016-11-30 13:21:11 +00:00
|
|
|
#include "src/parsing/parsing.h"
|
2016-01-26 10:38:37 +00:00
|
|
|
#include "src/parsing/preparser.h"
|
|
|
|
#include "test/fuzzer/fuzzer-support.h"
|
|
|
|
|
2017-05-17 10:36:10 +00:00
|
|
|
#include <cctype>
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
bool IsValidInput(const uint8_t* data, size_t size) {
|
|
|
|
std::list<char> parentheses;
|
|
|
|
const char* ptr = reinterpret_cast<const char*>(data);
|
|
|
|
|
|
|
|
for (size_t i = 0; i != size; ++i) {
|
|
|
|
// Check that all characters in the data are valid.
|
|
|
|
if (!(std::isspace(ptr[i]) || std::isprint(ptr[i]))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check balance of parentheses in the data.
|
|
|
|
switch (ptr[i]) {
|
|
|
|
case '(':
|
|
|
|
case '[':
|
|
|
|
case '{':
|
|
|
|
parentheses.push_back(ptr[i]);
|
|
|
|
break;
|
|
|
|
case ')':
|
|
|
|
if (parentheses.back() != '(') return false;
|
|
|
|
parentheses.pop_back();
|
|
|
|
break;
|
|
|
|
case ']':
|
|
|
|
if (parentheses.back() != '[') return false;
|
|
|
|
parentheses.pop_back();
|
|
|
|
break;
|
|
|
|
case '}':
|
|
|
|
if (parentheses.back() != '{') return false;
|
|
|
|
parentheses.pop_back();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return parentheses.empty();
|
|
|
|
}
|
|
|
|
|
2016-01-26 10:38:37 +00:00
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
2017-05-17 10:36:10 +00:00
|
|
|
if (!IsValidInput(data, size)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-26 10:38:37 +00:00
|
|
|
v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get();
|
|
|
|
v8::Isolate* isolate = support->GetIsolate();
|
|
|
|
|
|
|
|
v8::Isolate::Scope isolate_scope(isolate);
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Context::Scope context_scope(support->GetContext());
|
|
|
|
v8::TryCatch try_catch(isolate);
|
|
|
|
|
|
|
|
v8::internal::Isolate* i_isolate =
|
|
|
|
reinterpret_cast<v8::internal::Isolate*>(isolate);
|
|
|
|
v8::internal::Factory* factory = i_isolate->factory();
|
|
|
|
|
|
|
|
if (size > INT_MAX) return 0;
|
|
|
|
v8::internal::MaybeHandle<v8::internal::String> source =
|
|
|
|
factory->NewStringFromOneByte(
|
|
|
|
v8::internal::Vector<const uint8_t>(data, static_cast<int>(size)));
|
|
|
|
if (source.is_null()) return 0;
|
|
|
|
|
|
|
|
v8::internal::Handle<v8::internal::Script> script =
|
|
|
|
factory->NewScript(source.ToHandleChecked());
|
Reland of land: [Parse] ParseInfo owns the parsing Zone. (patchset #1 id:1 of https://codereview.chromium.org/2683733002/ )
Reason for revert:
False alarm, bot hiccup
Original issue's description:
> Revert of Reland: [Parse] ParseInfo owns the parsing Zone. (patchset #7 id:140001 of https://codereview.chromium.org/2632123006/ )
>
> Reason for revert:
> Speculative revert because of revert needed for https://codereview.chromium.org/2632123006
>
> Original issue's description:
> > Reland: [Parse] ParseInfo owns the parsing Zone.
> >
> > Moves ownership of the parsing Zone to ParseInfo with a shared_ptr. This is
> > in preperation for enabling background compilation jobs for inner functions
> > share the AST in the outer-function's parse zone memory (read-only), with the
> > and zone being released when all compilation jobs have completed.
> >
> > BUG=v8:5203,v8:5215
> >
> > Review-Url: https://codereview.chromium.org/2632123006
> > Cr-Original-Commit-Position: refs/heads/master@{#42993}
> > Committed: https://chromium.googlesource.com/v8/v8/+/14fb337200d5da09c77438ddd40bea935b1dc823
> > Review-Url: https://codereview.chromium.org/2632123006
> > Cr-Commit-Position: refs/heads/master@{#42996}
> > Committed: https://chromium.googlesource.com/v8/v8/+/9e7d5a6065470ca03411d4c8dbc61d1be5c3f84a
>
> TBR=marja@chromium.org,mstarzinger@chromium.org,ahaas@chromium.org,verwaest@chromium.org,rmcilroy@chromium.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=v8:5203,v8:5215
>
> Review-Url: https://codereview.chromium.org/2683733002
> Cr-Commit-Position: refs/heads/master@{#43008}
> Committed: https://chromium.googlesource.com/v8/v8/+/9fe08ec067051c5b46e694568bd01c6dba44cc4d
TBR=marja@chromium.org,mstarzinger@chromium.org,ahaas@chromium.org,verwaest@chromium.org,rmcilroy@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:5203,v8:5215
Review-Url: https://codereview.chromium.org/2679303003
Cr-Commit-Position: refs/heads/master@{#43015}
2017-02-07 20:46:47 +00:00
|
|
|
v8::internal::ParseInfo info(script);
|
2017-05-02 09:38:35 +00:00
|
|
|
if (!v8::internal::parsing::ParseProgram(&info, i_isolate)) {
|
|
|
|
i_isolate->OptionalRescheduleException(true);
|
|
|
|
}
|
2016-04-28 13:32:17 +00:00
|
|
|
isolate->RequestGarbageCollectionForTesting(
|
|
|
|
v8::Isolate::kFullGarbageCollection);
|
2016-01-26 10:38:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|