| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 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) { |
| 49 return true; | 49 return true; |
| 50 } | 50 } |
| 51 | 51 |
| 52 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) {} |
| 53 | 53 |
| 54 static bool RenderPage(const FPDF_DOCUMENT& doc, | 54 static bool RenderPage(const FPDF_DOCUMENT& doc, |
| 55 const FPDF_FORMHANDLE& form, | 55 const FPDF_FORMHANDLE& form, |
| 56 const int page_index) { | 56 const int page_index) { |
| 57 FPDF_PAGE page = FPDF_LoadPage(doc, page_index); | 57 FPDF_PAGE page = FPDF_LoadPage(doc, page_index); |
| 58 if (!page) { | 58 if (!page) |
| 59 return false; | 59 return false; |
| 60 } | 60 |
| 61 FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page); | 61 FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page); |
| 62 FORM_OnAfterLoadPage(page, form); | 62 FORM_OnAfterLoadPage(page, form); |
| 63 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_OPEN); | 63 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_OPEN); |
| 64 | 64 |
| 65 double scale = 1.0; | 65 const double scale = 1.0; |
| 66 int width = static_cast<int>(FPDF_GetPageWidth(page) * scale); | 66 int width = static_cast<int>(FPDF_GetPageWidth(page) * scale); |
| 67 int height = static_cast<int>(FPDF_GetPageHeight(page) * scale); | 67 int height = static_cast<int>(FPDF_GetPageHeight(page) * scale); |
| 68 | 68 |
| 69 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0); | 69 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0); |
| 70 if (!bitmap) { | 70 if (bitmap) { |
| 71 return false; | 71 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); |
| 72 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); |
| 73 |
| 74 FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0); |
| 75 |
| 76 FPDFBitmap_Destroy(bitmap); |
| 72 } | 77 } |
| 73 | |
| 74 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); | |
| 75 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); | |
| 76 | |
| 77 FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0); | |
| 78 | |
| 79 FPDFBitmap_Destroy(bitmap); | |
| 80 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_CLOSE); | 78 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_CLOSE); |
| 81 FORM_OnBeforeClosePage(page, form); | 79 FORM_OnBeforeClosePage(page, form); |
| 82 FPDFText_ClosePage(text_page); | 80 FPDFText_ClosePage(text_page); |
| 83 FPDF_ClosePage(page); | 81 FPDF_ClosePage(page); |
| 84 return true; | 82 return !!bitmap; |
| 85 } | 83 } |
| 86 | 84 |
| 87 static void RenderPdf(const char* pBuf, size_t len) { | 85 static void RenderPdf(const char* pBuf, size_t len) { |
| 88 IPDF_JSPLATFORM platform_callbacks; | 86 IPDF_JSPLATFORM platform_callbacks; |
| 89 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); | 87 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); |
| 90 platform_callbacks.version = 3; | 88 platform_callbacks.version = 3; |
| 91 platform_callbacks.app_alert = ExampleAppAlert; | 89 platform_callbacks.app_alert = ExampleAppAlert; |
| 92 platform_callbacks.Doc_gotoPage = ExampleDocGotoPage; | 90 platform_callbacks.Doc_gotoPage = ExampleDocGotoPage; |
| 93 | 91 |
| 94 FPDF_FORMFILLINFO form_callbacks; | 92 FPDF_FORMFILLINFO form_callbacks; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 FPDF_LIBRARY_CONFIG config; | 213 FPDF_LIBRARY_CONFIG config; |
| 216 UNSUPPORT_INFO unsupport_info; | 214 UNSUPPORT_INFO unsupport_info; |
| 217 }; | 215 }; |
| 218 | 216 |
| 219 static TestCase* testCase = new TestCase(); | 217 static TestCase* testCase = new TestCase(); |
| 220 | 218 |
| 221 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 219 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 222 RenderPdf(reinterpret_cast<const char*>(data), size); | 220 RenderPdf(reinterpret_cast<const char*>(data), size); |
| 223 return 0; | 221 return 0; |
| 224 } | 222 } |
| OLD | NEW |