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