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