| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This fuzzer is simplified & cleaned up pdfium/samples/pdfium_test.cc | 5 // This fuzzer is simplified & cleaned up pdfium/samples/pdfium_test.cc |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <limits.h> | 8 #include <limits.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <stdlib.h> | 10 #include <stdlib.h> |
| 11 #include <string.h> | 11 #include <string.h> |
| 12 |
| 13 #ifdef _MSC_VER |
| 14 #include <Windows.h> |
| 15 #else |
| 12 #include <unistd.h> | 16 #include <unistd.h> |
| 17 #endif |
| 13 | 18 |
| 14 #include <list> | 19 #include <list> |
| 15 #include <sstream> | 20 #include <sstream> |
| 16 #include <string> | 21 #include <string> |
| 17 #include <utility> | 22 #include <utility> |
| 18 #include <vector> | 23 #include <vector> |
| 19 | 24 |
| 20 #include "third_party/pdfium/public/fpdf_dataavail.h" | 25 #include "third_party/pdfium/public/fpdf_dataavail.h" |
| 21 #include "third_party/pdfium/public/fpdf_ext.h" | 26 #include "third_party/pdfium/public/fpdf_ext.h" |
| 22 #include "third_party/pdfium/public/fpdf_formfill.h" | 27 #include "third_party/pdfium/public/fpdf_formfill.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 RenderPage(doc, form, i); | 162 RenderPage(doc, form, i); |
| 158 } | 163 } |
| 159 | 164 |
| 160 FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC); | 165 FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC); |
| 161 FPDFDOC_ExitFormFillEnvironment(form); | 166 FPDFDOC_ExitFormFillEnvironment(form); |
| 162 FPDF_CloseDocument(doc); | 167 FPDF_CloseDocument(doc); |
| 163 FPDFAvail_Destroy(pdf_avail); | 168 FPDFAvail_Destroy(pdf_avail); |
| 164 } | 169 } |
| 165 | 170 |
| 166 std::string ProgramPath() { | 171 std::string ProgramPath() { |
| 172 #ifdef _MSC_VER |
| 173 wchar_t wpath[MAX_PATH]; |
| 174 char path[MAX_PATH]; |
| 175 DWORD res = GetModuleFileName(NULL, wpath, MAX_PATH); |
| 176 assert(res != 0); |
| 177 wcstombs(path, wpath, MAX_PATH); |
| 178 return std::string(path, res); |
| 179 #else |
| 167 char *path = new char[PATH_MAX + 1]; | 180 char *path = new char[PATH_MAX + 1]; |
| 168 assert(path); | 181 assert(path); |
| 169 ssize_t sz = readlink("/proc/self/exe", path, PATH_MAX); | 182 ssize_t sz = readlink("/proc/self/exe", path, PATH_MAX); |
| 170 assert(sz > 0); | 183 assert(sz > 0); |
| 171 std::string result(path, sz); | 184 std::string result(path, sz); |
| 172 delete[] path; | 185 delete[] path; |
| 173 return result; | 186 return result; |
| 187 #endif |
| 174 } | 188 } |
| 175 | 189 |
| 176 struct TestCase { | 190 struct TestCase { |
| 177 TestCase() { | 191 TestCase() { |
| 178 InitializeV8ForPDFium(ProgramPath(), "", &natives_blob, &snapshot_blob, | 192 InitializeV8ForPDFium(ProgramPath(), "", &natives_blob, &snapshot_blob, |
| 179 &platform); | 193 &platform); |
| 180 | 194 |
| 181 memset(&config, '\0', sizeof(config)); | 195 memset(&config, '\0', sizeof(config)); |
| 182 config.version = 2; | 196 config.version = 2; |
| 183 config.m_pUserFontPaths = nullptr; | 197 config.m_pUserFontPaths = nullptr; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 197 FPDF_LIBRARY_CONFIG config; | 211 FPDF_LIBRARY_CONFIG config; |
| 198 UNSUPPORT_INFO unsupport_info; | 212 UNSUPPORT_INFO unsupport_info; |
| 199 }; | 213 }; |
| 200 | 214 |
| 201 static TestCase* testCase = new TestCase(); | 215 static TestCase* testCase = new TestCase(); |
| 202 | 216 |
| 203 extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size) { | 217 extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size) { |
| 204 RenderPdf(reinterpret_cast<const char*>(data), size); | 218 RenderPdf(reinterpret_cast<const char*>(data), size); |
| 205 return 0; | 219 return 0; |
| 206 } | 220 } |
| OLD | NEW |