OLD | NEW |
(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 "test/fuzzer/wasm-section-fuzzers.h" |
| 6 |
| 7 #include "include/v8.h" |
| 8 #include "src/isolate.h" |
| 9 #include "src/wasm/encoder.h" |
| 10 #include "src/wasm/wasm-module.h" |
| 11 #include "src/zone.h" |
| 12 #include "test/cctest/wasm/wasm-module-runner.h" |
| 13 #include "test/fuzzer/fuzzer-support.h" |
| 14 |
| 15 using namespace v8::internal::wasm; |
| 16 |
| 17 int fuzz_wasm_section(WasmSection::Code section, const uint8_t* data, |
| 18 size_t size) { |
| 19 v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get(); |
| 20 v8::Isolate* isolate = support->GetIsolate(); |
| 21 v8::internal::Isolate* i_isolate = |
| 22 reinterpret_cast<v8::internal::Isolate*>(isolate); |
| 23 |
| 24 // Clear any pending exceptions from a prior run. |
| 25 if (i_isolate->has_pending_exception()) { |
| 26 i_isolate->clear_pending_exception(); |
| 27 } |
| 28 |
| 29 v8::Isolate::Scope isolate_scope(isolate); |
| 30 v8::HandleScope handle_scope(isolate); |
| 31 v8::Context::Scope context_scope(support->GetContext()); |
| 32 v8::TryCatch try_catch(isolate); |
| 33 |
| 34 v8::base::AccountingAllocator allocator; |
| 35 v8::internal::Zone zone(&allocator); |
| 36 |
| 37 ZoneBuffer buffer(&zone); |
| 38 buffer.write_u32(kWasmMagic); |
| 39 buffer.write_u32(kWasmVersion); |
| 40 const char* name = WasmSection::getName(section); |
| 41 size_t length = WasmSection::getNameLength(section); |
| 42 buffer.write_size(length); // Section name string size. |
| 43 buffer.write(reinterpret_cast<const uint8_t*>(name), length); |
| 44 buffer.write_u32v(static_cast<uint32_t>(size)); |
| 45 buffer.write(data, size); |
| 46 |
| 47 ErrorThrower thrower(i_isolate, "decoder"); |
| 48 |
| 49 std::unique_ptr<const WasmModule> module(testing::DecodeWasmModuleForTesting( |
| 50 i_isolate, &zone, thrower, buffer.begin(), buffer.end(), kWasmOrigin)); |
| 51 |
| 52 return 0; |
| 53 } |
OLD | NEW |