| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 #include "third_party/pdfium/public/fpdf_dataavail.h" | 27 #include "third_party/pdfium/public/fpdf_dataavail.h" |
| 28 #include "third_party/pdfium/public/fpdf_ext.h" | 28 #include "third_party/pdfium/public/fpdf_ext.h" |
| 29 #include "third_party/pdfium/public/fpdf_formfill.h" | 29 #include "third_party/pdfium/public/fpdf_formfill.h" |
| 30 #include "third_party/pdfium/public/fpdf_text.h" | 30 #include "third_party/pdfium/public/fpdf_text.h" |
| 31 #include "third_party/pdfium/public/fpdfview.h" | 31 #include "third_party/pdfium/public/fpdfview.h" |
| 32 #include "third_party/pdfium/testing/test_support.h" | 32 #include "third_party/pdfium/testing/test_support.h" |
| 33 | 33 |
| 34 #include "v8/include/v8.h" | 34 #include "v8/include/v8.h" |
| 35 | 35 |
| 36 static int ExampleAppAlert(IPDF_JSPLATFORM*, FPDF_WIDESTRING, FPDF_WIDESTRING, | 36 static int ExampleAppAlert(IPDF_JSPLATFORM*, |
| 37 int, int) { | 37 FPDF_WIDESTRING, |
| 38 FPDF_WIDESTRING, |
| 39 int, |
| 40 int) { |
| 38 return 0; | 41 return 0; |
| 39 } | 42 } |
| 40 | 43 |
| 41 static void ExampleDocGotoPage(IPDF_JSPLATFORM*, int pageNumber) { } | 44 static void ExampleDocGotoPage(IPDF_JSPLATFORM*, int pageNumber) {} |
| 42 | 45 |
| 43 static void ExampleUnsupportedHandler(UNSUPPORT_INFO*, int type) { } | 46 static void ExampleUnsupportedHandler(UNSUPPORT_INFO*, int type) {} |
| 44 | |
| 45 | 47 |
| 46 FPDF_BOOL Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { | 48 FPDF_BOOL Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { |
| 47 return true; | 49 return true; |
| 48 } | 50 } |
| 49 | 51 |
| 50 static void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) { } | 52 static void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) {} |
| 51 | 53 |
| 52 static bool RenderPage(const FPDF_DOCUMENT& doc, | 54 static bool RenderPage(const FPDF_DOCUMENT& doc, |
| 53 const FPDF_FORMHANDLE& form, | 55 const FPDF_FORMHANDLE& form, |
| 54 const int page_index) { | 56 const int page_index) { |
| 55 FPDF_PAGE page = FPDF_LoadPage(doc, page_index); | 57 FPDF_PAGE page = FPDF_LoadPage(doc, page_index); |
| 56 if (!page) { | 58 if (!page) { |
| 57 return false; | 59 return false; |
| 58 } | 60 } |
| 59 FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page); | 61 FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page); |
| 60 FORM_OnAfterLoadPage(page, form); | 62 FORM_OnAfterLoadPage(page, form); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 assert(sz > 0); | 187 assert(sz > 0); |
| 186 std::string result(path, sz); | 188 std::string result(path, sz); |
| 187 delete[] path; | 189 delete[] path; |
| 188 return result; | 190 return result; |
| 189 #endif | 191 #endif |
| 190 } | 192 } |
| 191 | 193 |
| 192 struct TestCase { | 194 struct TestCase { |
| 193 TestCase() { | 195 TestCase() { |
| 194 InitializeV8ForPDFium(ProgramPath(), "", &natives_blob, &snapshot_blob, | 196 InitializeV8ForPDFium(ProgramPath(), "", &natives_blob, &snapshot_blob, |
| 195 &platform); | 197 &platform); |
| 196 | 198 |
| 197 memset(&config, '\0', sizeof(config)); | 199 memset(&config, '\0', sizeof(config)); |
| 198 config.version = 2; | 200 config.version = 2; |
| 199 config.m_pUserFontPaths = nullptr; | 201 config.m_pUserFontPaths = nullptr; |
| 200 config.m_pIsolate = nullptr; | 202 config.m_pIsolate = nullptr; |
| 201 config.m_v8EmbedderSlot = 0; | 203 config.m_v8EmbedderSlot = 0; |
| 202 FPDF_InitLibraryWithConfig(&config); | 204 FPDF_InitLibraryWithConfig(&config); |
| 203 | 205 |
| 204 memset(&unsupport_info, '\0', sizeof(unsupport_info)); | 206 memset(&unsupport_info, '\0', sizeof(unsupport_info)); |
| 205 unsupport_info.version = 1; | 207 unsupport_info.version = 1; |
| 206 unsupport_info.FSDK_UnSupport_Handler = ExampleUnsupportedHandler; | 208 unsupport_info.FSDK_UnSupport_Handler = ExampleUnsupportedHandler; |
| 207 FSDK_SetUnSpObjProcessHandler(&unsupport_info); | 209 FSDK_SetUnSpObjProcessHandler(&unsupport_info); |
| 208 } | 210 } |
| 209 | 211 |
| 210 v8::Platform* platform; | 212 v8::Platform* platform; |
| 211 v8::StartupData natives_blob; | 213 v8::StartupData natives_blob; |
| 212 v8::StartupData snapshot_blob; | 214 v8::StartupData snapshot_blob; |
| 213 FPDF_LIBRARY_CONFIG config; | 215 FPDF_LIBRARY_CONFIG config; |
| 214 UNSUPPORT_INFO unsupport_info; | 216 UNSUPPORT_INFO unsupport_info; |
| 215 }; | 217 }; |
| 216 | 218 |
| 217 static TestCase* testCase = new TestCase(); | 219 static TestCase* testCase = new TestCase(); |
| 218 | 220 |
| 219 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 221 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 220 RenderPdf(reinterpret_cast<const char*>(data), size); | 222 RenderPdf(reinterpret_cast<const char*>(data), size); |
| 221 return 0; | 223 return 0; |
| 222 } | 224 } |
| OLD | NEW |