From 038740c2fbd27f5a6a0fad8903546ecb69a2f9a4 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 13 Sep 2017 13:22:54 -0700 Subject: Fix CPDFPathObjectFromFPDFPageObject() implementation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It should make sure the FPDF_PAGEOJECT passed in is actually a path. Change-Id: I89d0626dc350fd2f65b08282b276a4de2c3a7398 Reviewed-on: https://pdfium-review.googlesource.com/13710 Commit-Queue: Lei Zhang Reviewed-by: Nicolás Peña Reviewed-by: Henrique Nakashima --- fpdfsdk/fpdfeditpath.cpp | 37 ++++++++++++++++++------------------- fpdfsdk/fpdfview.cpp | 3 ++- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/fpdfsdk/fpdfeditpath.cpp b/fpdfsdk/fpdfeditpath.cpp index 19d47e6a44..2b33dee934 100644 --- a/fpdfsdk/fpdfeditpath.cpp +++ b/fpdfsdk/fpdfeditpath.cpp @@ -50,11 +50,11 @@ FPDFPath_SetStrokeColor(FPDF_PAGEOBJECT path, unsigned int G, unsigned int B, unsigned int A) { - if (!path || R > 255 || G > 255 || B > 255 || A > 255) + auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); + if (!pPathObj || R > 255 || G > 255 || B > 255 || A > 255) return false; float rgb[3] = {R / 255.f, G / 255.f, B / 255.f}; - auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); pPathObj->m_GeneralState.SetStrokeAlpha(A / 255.f); pPathObj->m_ColorState.SetStrokeColor( CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); @@ -68,10 +68,10 @@ FPDFPath_GetStrokeColor(FPDF_PAGEOBJECT path, unsigned int* G, unsigned int* B, unsigned int* A) { - if (!path || !R || !G || !B || !A) + auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); + if (!pPathObj || !R || !G || !B || !A) return false; - auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); uint32_t strokeRGB = pPathObj->m_ColorState.GetStrokeRGB(); *R = FXSYS_GetRValue(strokeRGB); *G = FXSYS_GetGValue(strokeRGB); @@ -83,10 +83,10 @@ FPDFPath_GetStrokeColor(FPDF_PAGEOBJECT path, FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_SetStrokeWidth(FPDF_PAGEOBJECT path, float width) { - if (!path || width < 0.0f) + auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); + if (!pPathObj || width < 0.0f) return false; - auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); pPathObj->m_GraphState.SetLineWidth(width); pPathObj->SetDirty(true); return true; @@ -105,10 +105,10 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_GetFillColor(FPDF_PAGEOBJECT path, unsigned int* G, unsigned int* B, unsigned int* A) { - if (!path || !R || !G || !B || !A) + auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); + if (!pPathObj || !R || !G || !B || !A) return false; - auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); uint32_t fillRGB = pPathObj->m_ColorState.GetFillRGB(); *R = FXSYS_GetRValue(fillRGB); *G = FXSYS_GetGValue(fillRGB); @@ -121,10 +121,10 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_GetFillColor(FPDF_PAGEOBJECT path, FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_MoveTo(FPDF_PAGEOBJECT path, float x, float y) { - if (!path) + auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); + if (!pPathObj) return false; - auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); pPathObj->m_Path.AppendPoint(CFX_PointF(x, y), FXPT_TYPE::MoveTo, false); pPathObj->SetDirty(true); return true; @@ -133,10 +133,10 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_MoveTo(FPDF_PAGEOBJECT path, FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_LineTo(FPDF_PAGEOBJECT path, float x, float y) { - if (!path) + auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); + if (!pPathObj) return false; - auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); pPathObj->m_Path.AppendPoint(CFX_PointF(x, y), FXPT_TYPE::LineTo, false); pPathObj->SetDirty(true); return true; @@ -149,10 +149,10 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_BezierTo(FPDF_PAGEOBJECT path, float y2, float x3, float y3) { - if (!path) + auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); + if (!pPathObj) return false; - auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); pPathObj->m_Path.AppendPoint(CFX_PointF(x1, y1), FXPT_TYPE::BezierTo, false); pPathObj->m_Path.AppendPoint(CFX_PointF(x2, y2), FXPT_TYPE::BezierTo, false); pPathObj->m_Path.AppendPoint(CFX_PointF(x3, y3), FXPT_TYPE::BezierTo, false); @@ -161,10 +161,10 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_BezierTo(FPDF_PAGEOBJECT path, } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_Close(FPDF_PAGEOBJECT path) { - if (!path) + auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); + if (!pPathObj) return false; - auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); if (pPathObj->m_Path.GetPoints().empty()) return false; @@ -176,10 +176,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_Close(FPDF_PAGEOBJECT path) { FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_SetDrawMode(FPDF_PAGEOBJECT path, int fillmode, FPDF_BOOL stroke) { - if (!path) - return false; - auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); + if (!pPathObj) + return false; if (fillmode == FPDF_FILLMODE_ALTERNATE) pPathObj->m_FillType = FXFILL_ALTERNATE; diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index 5bcc643ac1..0aaafe8afb 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -336,7 +336,8 @@ CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { } CPDF_PathObject* CPDFPathObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object) { - return static_cast(page_object); + auto* obj = CPDFPageObjectFromFPDFPageObject(page_object); + return obj ? obj->AsPath() : nullptr; } CPDF_PageObject* CPDFPageObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object) { -- cgit v1.2.3