/src/read_binary_interp_fuzzer.cc
Line | Count | Source |
1 | | // Copyright 2019 Google LLC |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #include <cstddef> |
16 | | #include <cstdint> |
17 | | |
18 | | #include <fuzzer/FuzzedDataProvider.h> |
19 | | |
20 | | #include "wabt/binary-reader.h" |
21 | | #include "wabt/interp/binary-reader-interp.h" |
22 | | #include "wabt/interp/interp.h" |
23 | | #include "wabt/ir.h" |
24 | | #include "wabt/option-parser.h" |
25 | | |
26 | 16.2k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
27 | 16.2k | wabt::Errors errors; |
28 | 16.2k | wabt::Features features; |
29 | 16.2k | wabt::interp::ModuleDesc module; |
30 | 16.2k | FuzzedDataProvider data_provider(data, size); |
31 | | |
32 | 16.2k | #define WABT_FEATURE(variable, flag, default_, help) \ |
33 | 308k | if (data_provider.ConsumeBool()) { features.enable_##variable(); } |
34 | 16.2k | #include "wabt/feature.def" |
35 | 16.2k | #undef WABT_FEATURE |
36 | | // Add only feature related options, but no logging, stop_on_first_error, etc. |
37 | 16.2k | wabt::ReadBinaryOptions options(features, nullptr, false, false, false); |
38 | 16.2k | std::vector<uint8_t> text = data_provider.ConsumeRemainingBytes<uint8_t>(); |
39 | 16.2k | ReadBinaryInterp("<fuzzer>", text.data(), text.size(), options, &errors, |
40 | 16.2k | &module); |
41 | 16.2k | return 0; |
42 | 16.2k | } |
43 | | |