Skip to content

Commit

Permalink
wasm/test: Set up fuzzing of the module validation
Browse files Browse the repository at this point in the history
  • Loading branch information
robinlinden committed Nov 19, 2024
1 parent 834fd1b commit e293c43
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions wasm/validation_fuzz_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: 2024 Robin Lindén <[email protected]>
//
// SPDX-License-Identifier: BSD-2-Clause

#include "wasm/validation.h"

#include "wasm/byte_code_parser.h"

#include <cstddef>
#include <cstdint>
#include <sstream>
#include <string>
#include <tuple>

extern "C" int LLVMFuzzerTestOneInput(std::uint8_t const *data, std::size_t size);

extern "C" int LLVMFuzzerTestOneInput(std::uint8_t const *data, std::size_t size) {
auto module = wasm::ByteCodeParser::parse_module(
std::stringstream{std::string{reinterpret_cast<char const *>(data), size}});
if (!module) {
return 0;
}

std::ignore = wasm::validation::validate(*module);
return 0;
}

0 comments on commit e293c43

Please sign in to comment.