Line | Count | Source |
1 | | /* Copyright 2024 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 "spirv_common.hpp" |
14 | | #include "spirv_parser.hpp" |
15 | | #include <cstdint> |
16 | | #include <vector> |
17 | | |
18 | | using namespace spirv_cross; |
19 | | |
20 | 610 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
21 | | // Skip this iteration if data is not enough |
22 | 610 | if (size < (sizeof(uint32_t) * 5) || (size % 4 != 0)) { |
23 | 10 | return 0; |
24 | 10 | } |
25 | | |
26 | | // Initialise objects and random data |
27 | 600 | std::vector<uint32_t> spirv_data((uint32_t *)data, (uint32_t *)(data + size)); |
28 | | |
29 | | // Set magic number, since this is needed to get past initial checks. |
30 | 600 | spirv_data[0] = 0x07230203; |
31 | 600 | spirv_data[1] = 0x10600; |
32 | | |
33 | 600 | Parser parser(spirv_data); |
34 | 600 | ParsedIR &ir = parser.get_parsed_ir(); |
35 | 600 | SPIRFunction *current_function = nullptr; |
36 | 600 | SPIRBlock *current_block = nullptr; |
37 | | |
38 | 600 | try { |
39 | 600 | parser.parse(); |
40 | 600 | } catch (...) { |
41 | 438 | } |
42 | | |
43 | 600 | return 0; |
44 | 600 | } |