2016-08-29 13:55:41 +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.
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2019-05-22 07:55:37 +00:00
|
|
|
#include "src/execution/isolate.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
|
|
|
#include "src/objects/objects.h"
|
2016-09-29 11:29:05 +00:00
|
|
|
#include "src/wasm/wasm-module-builder.h"
|
2016-10-05 11:59:47 +00:00
|
|
|
#include "test/common/wasm/test-signatures.h"
|
2017-05-08 09:22:54 +00:00
|
|
|
#include "test/fuzzer/wasm-fuzzer-common.h"
|
2016-09-22 12:54:52 +00:00
|
|
|
|
2017-09-01 13:20:46 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace wasm {
|
|
|
|
namespace fuzzer {
|
2017-08-09 08:11:21 +00:00
|
|
|
|
2017-05-08 09:22:54 +00:00
|
|
|
class WasmCodeFuzzer : public WasmExecutionFuzzer {
|
2021-07-05 14:08:41 +00:00
|
|
|
bool GenerateModule(Isolate* isolate, Zone* zone,
|
2021-07-16 14:46:36 +00:00
|
|
|
base::Vector<const uint8_t> data, ZoneBuffer* buffer,
|
|
|
|
bool liftoff_as_reference) override {
|
2017-05-08 09:22:54 +00:00
|
|
|
TestSignatures sigs;
|
|
|
|
WasmModuleBuilder builder(zone);
|
|
|
|
WasmFunctionBuilder* f = builder.AddFunction(sigs.i_iii());
|
2019-04-29 11:06:49 +00:00
|
|
|
f->EmitCode(data.begin(), static_cast<uint32_t>(data.size()));
|
2017-05-08 09:22:54 +00:00
|
|
|
uint8_t end_opcode = kExprEnd;
|
|
|
|
f->EmitCode(&end_opcode, 1);
|
2021-06-17 15:43:55 +00:00
|
|
|
builder.AddExport(base::CStrVector("main"), f);
|
2017-05-08 09:22:54 +00:00
|
|
|
|
2017-08-29 08:47:47 +00:00
|
|
|
builder.SetMaxMemorySize(32);
|
2019-07-08 11:44:42 +00:00
|
|
|
builder.WriteTo(buffer);
|
2017-05-08 09:22:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2016-09-12 12:26:37 +00:00
|
|
|
|
2016-08-29 13:55:41 +00:00
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
2018-11-20 14:41:36 +00:00
|
|
|
WasmCodeFuzzer().FuzzWasmModule({data, size});
|
|
|
|
return 0;
|
2016-08-29 13:55:41 +00:00
|
|
|
}
|
2017-09-01 13:20:46 +00:00
|
|
|
|
|
|
|
} // namespace fuzzer
|
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|