Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(587)

Side by Side Diff: test/fuzzer/wasm-section-fuzzers.cc

Issue 2345593003: [wasm] Master CL for Binary 0xC changes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix test failures and TSAN races. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/fuzzer/wasm-section-fuzzers.h ('k') | test/fuzzer/wasm-types-section.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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(WasmSection::Code section, const uint8_t* data, 18 static const char* kNameString = "name";
19 static const size_t kNameStringLength = 4;
20
21 int fuzz_wasm_section(WasmSectionCode section, const uint8_t* data,
19 size_t size) { 22 size_t size) {
20 v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get(); 23 v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get();
21 v8::Isolate* isolate = support->GetIsolate(); 24 v8::Isolate* isolate = support->GetIsolate();
22 v8::internal::Isolate* i_isolate = 25 v8::internal::Isolate* i_isolate =
23 reinterpret_cast<v8::internal::Isolate*>(isolate); 26 reinterpret_cast<v8::internal::Isolate*>(isolate);
24 27
25 // Clear any pending exceptions from a prior run. 28 // Clear any pending exceptions from a prior run.
26 if (i_isolate->has_pending_exception()) { 29 if (i_isolate->has_pending_exception()) {
27 i_isolate->clear_pending_exception(); 30 i_isolate->clear_pending_exception();
28 } 31 }
29 32
30 v8::Isolate::Scope isolate_scope(isolate); 33 v8::Isolate::Scope isolate_scope(isolate);
31 v8::HandleScope handle_scope(isolate); 34 v8::HandleScope handle_scope(isolate);
32 v8::Context::Scope context_scope(support->GetContext()); 35 v8::Context::Scope context_scope(support->GetContext());
33 v8::TryCatch try_catch(isolate); 36 v8::TryCatch try_catch(isolate);
34 37
35 v8::internal::AccountingAllocator allocator; 38 v8::internal::AccountingAllocator allocator;
36 v8::internal::Zone zone(&allocator); 39 v8::internal::Zone zone(&allocator);
37 40
38 ZoneBuffer buffer(&zone); 41 ZoneBuffer buffer(&zone);
39 buffer.write_u32(kWasmMagic); 42 buffer.write_u32(kWasmMagic);
40 buffer.write_u32(kWasmVersion); 43 buffer.write_u32(kWasmVersion);
41 const char* name = WasmSection::getName(section); 44 if (section == kNameSectionCode) {
42 size_t length = WasmSection::getNameLength(section); 45 buffer.write_u8(kUnknownSectionCode);
43 buffer.write_size(length); // Section name string size. 46 buffer.write_size(size + kNameStringLength + 1);
44 buffer.write(reinterpret_cast<const uint8_t*>(name), length); 47 buffer.write_u8(kNameStringLength);
45 buffer.write_u32v(static_cast<uint32_t>(size)); 48 buffer.write(reinterpret_cast<const uint8_t*>(kNameString),
46 buffer.write(data, size); 49 kNameStringLength);
50 buffer.write(data, size);
51 } else {
52 buffer.write_u8(section);
53 buffer.write_size(size);
54 buffer.write(data, size);
55 }
47 56
48 ErrorThrower thrower(i_isolate, "decoder"); 57 ErrorThrower thrower(i_isolate, "decoder");
49 58
50 std::unique_ptr<const WasmModule> module(testing::DecodeWasmModuleForTesting( 59 std::unique_ptr<const WasmModule> module(testing::DecodeWasmModuleForTesting(
51 i_isolate, &zone, &thrower, buffer.begin(), buffer.end(), kWasmOrigin)); 60 i_isolate, &zone, &thrower, buffer.begin(), buffer.end(), kWasmOrigin));
52 61
53 return 0; 62 return 0;
54 } 63 }
OLDNEW
« no previous file with comments | « test/fuzzer/wasm-section-fuzzers.h ('k') | test/fuzzer/wasm-types-section.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698