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