Coverage Report

Created: 2026-08-14 06:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/filestorage_read_file_fuzzer.cc
Line
Count
Source
1
// Copyright 2020 Google Inc.
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
#include <string>
18
19
#include <opencv2/opencv.hpp>
20
#include "fuzzer_temp_file.h"
21
22
7.19k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
23
7.19k
  const FuzzerTemporaryFile temp_file(data, size);
24
25
7.19k
  try {
26
7.19k
    cv::FileStorage storage;
27
7.19k
    if (!storage.open(temp_file.filename(), cv::FileStorage::READ)) {
28
4
      return 0;
29
4
    }
30
31
7.19k
    cv::FileNode root = storage.root();
32
16.2k
    for (cv::FileNodeIterator it = root.begin(); it != root.end(); ++it) {
33
9.66k
      cv::FileNode node = *it;
34
9.66k
      const std::string node_name = node.name();
35
9.66k
      const int node_type = node.type();
36
37
9.66k
      switch (node_type) {
38
739
        case cv::FileNode::INT:
39
739
          (void)static_cast<int>(node);
40
739
          break;
41
908
        case cv::FileNode::REAL:
42
908
          (void)static_cast<double>(node);
43
908
          break;
44
2.55k
        case cv::FileNode::STRING:
45
2.55k
          (void)static_cast<std::string>(node);
46
2.55k
          break;
47
2.16k
        case cv::FileNode::SEQ:
48
4.69k
        case cv::FileNode::MAP: {
49
4.69k
          for (cv::FileNodeIterator child_it = node.begin();
50
1.69M
               child_it != node.end(); ++child_it) {
51
1.69M
            cv::FileNode child = *child_it;
52
1.69M
            (void)child.name();
53
1.69M
            (void)child.type();
54
1.69M
          }
55
4.69k
          break;
56
2.16k
        }
57
339
        default:
58
339
          break;
59
9.66k
      }
60
9.66k
    }
61
62
6.57k
    storage.release();
63
6.57k
  } catch (const cv::Exception&) {
64
5.86k
  } catch (...) {
65
1
  }
66
67
7.19k
  return 0;
68
7.19k
}