diff options
author | Nicolas Pena <npm@chromium.org> | 2018-04-16 17:41:47 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-16 17:41:47 +0000 |
commit | d08667c174fa302d7dd05ab0b33d61b91fcda63c (patch) | |
tree | 9a1252f7e8f2fc582cfaf083149206b011ade946 | |
parent | 4125ab6efc146527e63ee2b1dc0e584919a862ca (diff) | |
download | pdfium-d08667c174fa302d7dd05ab0b33d61b91fcda63c.tar.xz |
Check that CFX_DIBitmap::Create calls succeeds in fpdf_view
CFX_DIBitmap::Create returns false upon failure, so the return value of
this method should be checked most of the time. This CL fixes the calls
from fpdf_view.cpp.
Bug: pdfium:983
Change-Id: I5782d2859c5b2a2e0c540b80510d7c98c01c04f3
Reviewed-on: https://pdfium-review.googlesource.com/30750
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r-- | fpdfsdk/fpdf_view.cpp | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp index cd8edbbdd2..d21448bc53 100644 --- a/fpdfsdk/fpdf_view.cpp +++ b/fpdfsdk/fpdf_view.cpp @@ -460,7 +460,9 @@ RetainPtr<CFX_DIBitmap> GetMaskBitmap(CPDF_Page* pPage, // Create a new bitmap to transfer part of the page bitmap to. RetainPtr<CFX_DIBitmap> pDst = pdfium::MakeRetain<CFX_DIBitmap>(); - pDst->Create(bitmap_area->Width(), bitmap_area->Height(), FXDIB_Argb); + if (!pDst->Create(bitmap_area->Width(), bitmap_area->Height(), FXDIB_Argb)) + return nullptr; + pDst->Clear(0x00ffffff); pDst->TransferBitmap(0, 0, bitmap_area->Width(), bitmap_area->Height(), pSrc, bitmap_area->left, bitmap_area->top); @@ -477,7 +479,9 @@ void RenderBitmap(CFX_RenderDevice* device, // Create a new bitmap from the old one RetainPtr<CFX_DIBitmap> pDst = pdfium::MakeRetain<CFX_DIBitmap>(); - pDst->Create(size_x_bm, size_y_bm, FXDIB_Rgb32); + if (!pDst->Create(size_x_bm, size_y_bm, FXDIB_Rgb32)) + return; + pDst->Clear(0xffffffff); pDst->CompositeBitmap(0, 0, size_x_bm, size_y_bm, pSrc, 0, 0, FXDIB_BLEND_NORMAL, nullptr, false); @@ -520,6 +524,8 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPage(HDC dc, const bool bHasMask = pPage->HasImageMask() && !bNewBitmap; if (bNewBitmap || bHasMask) { pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); + // Create will probably work fine even if it fails here: we will just attach + // a zero-sized bitmap to |pDevice|. pBitmap->Create(size_x, size_y, FXDIB_Argb); pBitmap->Clear(0x00ffffff); CFX_DefaultRenderDevice* pDevice = new CFX_DefaultRenderDevice; @@ -580,17 +586,19 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPage(HDC dc, } } else if (bNewBitmap) { CFX_WindowsRenderDevice WinDC(dc); + bool bitsStretched = false; if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { auto pDst = pdfium::MakeRetain<CFX_DIBitmap>(); - int pitch = pBitmap->GetPitch(); - pDst->Create(size_x, size_y, FXDIB_Rgb32); - memset(pDst->GetBuffer(), -1, pitch * size_y); - pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0, - FXDIB_BLEND_NORMAL, nullptr, false); - WinDC.StretchDIBits(pDst, 0, 0, size_x, size_y); - } else { - WinDC.SetDIBits(pBitmap, 0, 0); + if (pDst->Create(size_x, size_y, FXDIB_Rgb32)) { + memset(pDst->GetBuffer(), -1, pBitmap->GetPitch() * size_y); + pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0, + FXDIB_BLEND_NORMAL, nullptr, false); + WinDC.StretchDIBits(pDst, 0, 0, size_x, size_y); + bitsStretched = true; + } } + if (!bitsStretched) + WinDC.SetDIBits(pBitmap, 0, 0); } pPage->SetRenderContext(nullptr); @@ -814,8 +822,10 @@ FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFBitmap_CreateEx(int width, return nullptr; } auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); - pBitmap->Create(width, height, fx_format, static_cast<uint8_t*>(first_scan), - stride); + if (!pBitmap->Create(width, height, fx_format, + static_cast<uint8_t*>(first_scan), stride)) { + return nullptr; + } return pBitmap.Leak(); } |