Coverage Report

Created: 2026-08-14 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/read_binary_ir_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-ir.h"
21
#include "wabt/binary-reader.h"
22
#include "wabt/binary-writer.h"
23
#include "wabt/ir.h"
24
#include "wabt/option-parser.h"
25
#include "wabt/stream.h"
26
#include "wabt/validator.h"
27
#include "wabt/wat-writer.h"
28
29
21.1k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
30
21.1k
  wabt::Errors errors;
31
21.1k
  wabt::Module module;
32
21.1k
  wabt::Features features;
33
21.1k
  FuzzedDataProvider data_provider(data, size);
34
21.1k
#define WABT_FEATURE(variable, flag, default_, help) \
35
443k
  if (data_provider.ConsumeBool()) { features.enable_##variable(); }
36
21.1k
#include "wabt/feature.def"
37
21.1k
#undef WABT_FEATURE
38
  // Add only feature related options, but no logging, stop_on_first_error, etc.
39
21.1k
  wabt::ReadBinaryOptions options(features, nullptr,
40
21.1k
                                  /*read_debug_names=*/false,
41
21.1k
                                  /*stop_on_first_error=*/true,
42
21.1k
                                  /*fail_on_custom_section_error=*/false);
43
21.1k
  std::vector<uint8_t> text = data_provider.ConsumeRemainingBytes<uint8_t>();
44
21.1k
  if (wabt::Succeeded(wabt::ReadBinaryIr("", text.data(), text.size(), options, &errors, &module))) {
45
9.86k
    wabt::ValidateOptions validate_options(features);
46
9.86k
    if (wabt::Succeeded(wabt::ValidateModule(&module, &errors, validate_options))) {
47
3.48k
      wabt::MemoryStream stream;
48
3.48k
      wabt::WriteBinaryOptions write_binary_options;
49
3.48k
      wabt::WriteBinaryModule(&stream, &module, write_binary_options);
50
51
3.48k
      wabt::WriteWatOptions write_wat_options(features);
52
3.48k
      wabt::WriteWat(&stream, &module, write_wat_options);
53
3.48k
    }
54
9.86k
  }
55
21.1k
  return 0;
56
21.1k
}
57