summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-05-08 11:53:53 -0700
committerTom Sepez <tsepez@chromium.org>2015-05-08 11:53:53 -0700
commit17ea732e8c8bba793aa57644f2325eeaaf4a1cbd (patch)
tree85d9cc664672d7b5e67ebf648fa12221ed886b3a
parent470408c2ffe71e99cebad0d1d6887f1723f02cef (diff)
downloadpdfium-17ea732e8c8bba793aa57644f2325eeaaf4a1cbd.tar.xz
Better error from pdfium_test when page too big to render.
BUG=pdfium:114 R=thestig@chromium.org Review URL: https://codereview.chromium.org/1124423006
-rw-r--r--fpdfsdk/src/fpdfview.cpp9
-rw-r--r--samples/pdfium_test.cc6
2 files changed, 12 insertions, 3 deletions
diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp
index 3207ebe336..3c0e010465 100644
--- a/fpdfsdk/src/fpdfview.cpp
+++ b/fpdfsdk/src/fpdfview.cpp
@@ -11,6 +11,7 @@
#include "../include/fpdf_progressive.h"
#include "../include/fpdf_ext.h"
#include "../../../core/src/fxcrt/fx_safe_types.h"
+#include "../../third_party/base/nonstd_unique_ptr.h"
#include "../../third_party/base/numerics/safe_conversions_impl.h"
CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess)
@@ -597,9 +598,11 @@ DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, int start_x, int start_
DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, int height, int alpha)
{
- CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
- pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32);
- return pBitmap;
+ nonstd::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap);
+ if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) {
+ return NULL;
+ }
+ return pBitmap.release();
}
DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width, int height, int format, void* first_scan, int stride)
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
index 068dbaa767..d473c4716a 100644
--- a/samples/pdfium_test.cc
+++ b/samples/pdfium_test.cc
@@ -505,6 +505,12 @@ void RenderPdf(const std::string& name, const char* pBuf, size_t len,
int height = static_cast<int>(FPDF_GetPageHeight(page) * scale);
FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0);
+ if (!bitmap) {
+ fprintf(stderr, "Page was too large to be rendered.\n");
+ bad_pages++;
+ continue;
+ }
+
FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF);
FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0);
rendered_pages ++;