Coverage Report

Created: 2026-08-14 06:41

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
17.3k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
19
17.3k
  WasmEdge::Configure Conf;
20
17.3k
  Conf.addProposal(WasmEdge::Proposal::Component);
21
22
17.3k
  WasmEdge::Loader::Loader Loader(Conf);
23
17.3k
  auto ParseResult =
24
17.3k
      Loader.parseWasmUnit(WasmEdge::Span<const uint8_t>(Data, Size));
25
17.3k
  if (!ParseResult) {
26
11.9k
    return 0;
27
11.9k
  }
28
29
5.45k
  auto &Unit = *ParseResult;
30
5.45k
  WasmEdge::Validator::Validator Validator(Conf);
31
5.45k
  if (auto *Comp =
32
5.45k
          std::get_if<std::unique_ptr<WasmEdge::AST::Component::Component>>(
33
5.45k
              &Unit)) {
34
4.36k
    Validator.validate(**Comp);
35
4.36k
  } else if (auto *Mod =
36
1.08k
                 std::get_if<std::unique_ptr<WasmEdge::AST::Module>>(&Unit)) {
37
1.08k
    Validator.validate(**Mod);
38
1.08k
  }
39
40
5.45k
  return 0;
41
17.3k
}