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