Coverage Report

Created: 2025-06-13 06:48

/src/fuzz_json.cpp
Line
Count
Source
1
/* Copyright 2023 Google LLC
2
Licensed under the Apache License, Version 2.0 (the "License");
3
you may not use this file except in compliance with the License.
4
You may obtain a copy of the License at
5
      http://www.apache.org/licenses/LICENSE-2.0
6
Unless required by applicable law or agreed to in writing, software
7
distributed under the License is distributed on an "AS IS" BASIS,
8
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
See the License for the specific language governing permissions and
10
limitations under the License.
11
*/
12
13
#include <fstream>
14
#include <iostream>
15
#include <string>
16
17
#include <stdint.h>
18
#include <stdio.h>
19
#include <stdlib.h>
20
21
#include "json.hpp"
22
23
323
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
24
323
  std::string input(reinterpret_cast<const char *>(data), size);
25
26
323
  char *fuzz_filename = "/tmp/fuzz.json";
27
323
  std::ofstream(fuzz_filename, std::ios::binary).write(input.c_str(), size);
28
29
323
  std::ifstream fs(fuzz_filename);
30
323
  dnnl::impl::graph::utils::json::json_reader_t read(&fs);
31
323
  dnnl::impl::graph::utils::json::read_helper_t helper;
32
323
  try {
33
323
    helper.read_fields(&read);
34
323
  } catch (...) {
35
115
  }
36
37
323
  return 0;
38
323
}