1 // Copyright 2018 The Dawn Authors
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 <cstdint>
16 #include <cstdlib>
17 #include <iostream>
18 #include <vector>
19
20 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
21
main(int argc,char ** argv)22 int main(int argc, char** argv) {
23 if (argc != 2) {
24 std::cout << "Usage: <standalone reproducer> [FILE]" << std::endl;
25 return 1;
26 }
27
28 std::cout << "WARNING: this is just a best-effort reproducer for fuzzer issues in standalone "
29 << "Dawn builds. For the real fuzzer, please build inside Chromium." << std::endl;
30
31 const char* filename = argv[1];
32 std::cout << "Reproducing using file: " << filename << std::endl;
33
34 std::vector<char> data;
35 {
36 FILE* file = fopen(filename, "rb");
37 if (!file) {
38 std::cerr << "Failed to open " << filename << std::endl;
39 return 1;
40 }
41
42 fseek(file, 0, SEEK_END);
43 long tellFileSize = ftell(file);
44 if (tellFileSize <= 0) {
45 std::cerr << "Input file of incorrect size: " << filename << std::endl;
46 return 1;
47 }
48 fseek(file, 0, SEEK_SET);
49
50 size_t fileSize = static_cast<size_t>(tellFileSize);
51 data.resize(fileSize);
52
53 size_t bytesRead = fread(data.data(), sizeof(char), fileSize, file);
54 fclose(file);
55 if (bytesRead != fileSize) {
56 std::cerr << "Failed to read " << filename << std::endl;
57 return 1;
58 }
59 }
60
61 return LLVMFuzzerTestOneInput(reinterpret_cast<const uint8_t*>(data.data()), data.size());
62 }
63