Coverage Report

Created: 2026-07-16 07:09

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