Coverage Report

Created: 2026-05-16 06:40

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
6.21k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
23
6.21k
  const FuzzerTemporaryFile temp_file(data, size);
24
25
6.21k
  try {
26
6.21k
    cv::FileStorage storage;
27
6.21k
    if (!storage.open(temp_file.filename(), cv::FileStorage::READ)) {
28
4
      return 0;
29
4
    }
30
31
6.21k
    cv::FileNode root = storage.root();
32
14.0k
    for (cv::FileNodeIterator it = root.begin(); it != root.end(); ++it) {
33
8.36k
      cv::FileNode node = *it;
34
8.36k
      const std::string node_name = node.name();
35
8.36k
      const int node_type = node.type();
36
37
8.36k
      switch (node_type) {
38
359
        case cv::FileNode::INT:
39
359
          (void)static_cast<int>(node);
40
359
          break;
41
731
        case cv::FileNode::REAL:
42
731
          (void)static_cast<double>(node);
43
731
          break;
44
2.67k
        case cv::FileNode::STRING:
45
2.67k
          (void)static_cast<std::string>(node);
46
2.67k
          break;
47
1.91k
        case cv::FileNode::SEQ:
48
3.94k
        case cv::FileNode::MAP: {
49
3.94k
          for (cv::FileNodeIterator child_it = node.begin();
50
1.56M
               child_it != node.end(); ++child_it) {
51
1.56M
            cv::FileNode child = *child_it;
52
1.56M
            (void)child.name();
53
1.56M
            (void)child.type();
54
1.56M
          }
55
3.94k
          break;
56
1.91k
        }
57
275
        default:
58
275
          break;
59
8.36k
      }
60
8.36k
    }
61
62
5.67k
    storage.release();
63
5.67k
  } catch (const cv::Exception&) {
64
5.21k
  } catch (...) {
65
1
  }
66
67
6.21k
  return 0;
68
6.21k
}