Coverage Report

Created: 2026-09-28 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/WasmEdge/tools/fuzz/component.cpp
Line
Count
Source
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: 2019-2026 Second State INC
3
4
#include "common/configure.h"
5
#include "common/span.h"
6
#include "loader/loader.h"
7
#include "validator/validator.h"
8
9
#include <cstddef>
10
#include <cstdint>
11
#include <memory>
12
#include <variant>
13
14
// Fuzz the WebAssembly Component Model loader + validator on untrusted bytes.
15
// The Component proposal routes parseWasmUnit() through the component decoder
16
// (AST::Component) and component_validator.cpp, which the existing core-module
17
// driver fuzzer never reaches.
18
21.4k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
19
21.4k
  WasmEdge::Configure Conf;
20
21.4k
  Conf.addProposal(WasmEdge::Proposal::Component);
21
22
21.4k
  WasmEdge::Loader::Loader Loader(Conf);
23
21.4k
  auto ParseResult =
24
21.4k
      Loader.parseWasmUnit(WasmEdge::Span<const uint8_t>(Data, Size));
25
21.4k
  if (!ParseResult) {
26
12.1k
    return 0;
27
12.1k
  }
28
29
9.36k
  auto &Unit = *ParseResult;
30
9.36k
  WasmEdge::Validator::Validator Validator(Conf);
31
9.36k
  if (auto *Comp =
32
9.36k
          std::get_if<std::unique_ptr<WasmEdge::AST::Component::Component>>(
33
9.36k
              &Unit)) {
34
5.98k
    Validator.validate(**Comp);
35
5.98k
  } else if (auto *Mod =
36
3.38k
                 std::get_if<std::unique_ptr<WasmEdge::AST::Module>>(&Unit)) {
37
3.38k
    Validator.validate(**Mod);
38
3.38k
  }
39
40
9.36k
  return 0;
41
21.4k
}