diff options
author | Lei Zhang <thestig@chromium.org> | 2017-04-26 15:22:00 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-27 23:22:12 +0000 |
commit | 66568bcd683dd7b18672cb3aebca4487e9203519 (patch) | |
tree | 7297841771a796bafd3d0d17dd47b7b0e394d933 | |
parent | ba817506edcb26e0acf497111e7684e39dadaf04 (diff) | |
download | pdfium-66568bcd683dd7b18672cb3aebca4487e9203519.tar.xz |
Assert CPDF_Pattern always has a valid CPDF_Document pointer.
Same for CPDF_DocPageData.
Change-Id: I8f2f559123dbb2f3623d957e4074d5f9d191797f
Reviewed-on: https://pdfium-review.googlesource.com/4501
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
-rw-r--r-- | core/fpdfapi/page/cpdf_color.cpp | 8 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_docpagedata.cpp | 6 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_pattern.cpp | 16 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_pattern.h | 8 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_shadingpattern.cpp | 18 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_tilingpattern.cpp | 22 |
6 files changed, 41 insertions, 37 deletions
diff --git a/core/fpdfapi/page/cpdf_color.cpp b/core/fpdfapi/page/cpdf_color.cpp index 59ce6dab28..6e772aadb1 100644 --- a/core/fpdfapi/page/cpdf_color.cpp +++ b/core/fpdfapi/page/cpdf_color.cpp @@ -31,7 +31,7 @@ void CPDF_Color::ReleaseBuffer() { PatternValue* pvalue = (PatternValue*)m_pBuffer; CPDF_Pattern* pPattern = pvalue->m_pCountedPattern ? pvalue->m_pCountedPattern->get() : nullptr; - if (pPattern && pPattern->document()) { + if (pPattern) { CPDF_DocPageData* pPageData = pPattern->document()->GetPageData(); if (pPageData) pPageData->ReleasePattern(pPattern->pattern_obj()); @@ -89,7 +89,7 @@ void CPDF_Color::SetValue(CPDF_Pattern* pPattern, float* comps, int ncomps) { CPDF_DocPageData* pDocPageData = nullptr; PatternValue* pvalue = (PatternValue*)m_pBuffer; - if (pvalue->m_pPattern && pvalue->m_pPattern->document()) { + if (pvalue->m_pPattern) { pDocPageData = pvalue->m_pPattern->document()->GetPageData(); if (pDocPageData) pDocPageData->ReleasePattern(pvalue->m_pPattern->pattern_obj()); @@ -100,7 +100,7 @@ void CPDF_Color::SetValue(CPDF_Pattern* pPattern, float* comps, int ncomps) { memcpy(pvalue->m_Comps, comps, ncomps * sizeof(float)); pvalue->m_pCountedPattern = nullptr; - if (pPattern && pPattern->document()) { + if (pPattern) { if (!pDocPageData) pDocPageData = pPattern->document()->GetPageData(); @@ -129,7 +129,7 @@ void CPDF_Color::Copy(const CPDF_Color* pSrc) { PatternValue* pValue = reinterpret_cast<PatternValue*>(m_pBuffer); CPDF_Pattern* pPattern = pValue->m_pPattern; - if (pPattern && pPattern->document()) { + if (pPattern) { pValue->m_pPattern = pPattern->document()->GetPageData()->GetPattern( pPattern->pattern_obj(), false, pPattern->parent_matrix()); } diff --git a/core/fpdfapi/page/cpdf_docpagedata.cpp b/core/fpdfapi/page/cpdf_docpagedata.cpp index 5e13740c21..58e81559ea 100644 --- a/core/fpdfapi/page/cpdf_docpagedata.cpp +++ b/core/fpdfapi/page/cpdf_docpagedata.cpp @@ -28,7 +28,9 @@ #include "third_party/base/stl_util.h" CPDF_DocPageData::CPDF_DocPageData(CPDF_Document* pPDFDoc) - : m_pPDFDoc(pPDFDoc), m_bForceClear(false) {} + : m_pPDFDoc(pPDFDoc), m_bForceClear(false) { + assert(m_pPDFDoc); +} CPDF_DocPageData::~CPDF_DocPageData() { Clear(false); @@ -330,7 +332,7 @@ CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, pPattern = pdfium::MakeUnique<CPDF_ShadingPattern>(m_pPDFDoc, pPatternObj, true, matrix); } else { - CPDF_Dictionary* pDict = pPatternObj ? pPatternObj->GetDict() : nullptr; + CPDF_Dictionary* pDict = pPatternObj->GetDict(); if (pDict) { int type = pDict->GetIntegerFor("PatternType"); if (type == CPDF_Pattern::TILING) { diff --git a/core/fpdfapi/page/cpdf_pattern.cpp b/core/fpdfapi/page/cpdf_pattern.cpp index b0a2d81bca..88e5dee35c 100644 --- a/core/fpdfapi/page/cpdf_pattern.cpp +++ b/core/fpdfapi/page/cpdf_pattern.cpp @@ -6,13 +6,17 @@ #include "core/fpdfapi/page/cpdf_pattern.h" -CPDF_Pattern::CPDF_Pattern(PatternType type, - CPDF_Document* pDoc, +#include "core/fpdfapi/parser/cpdf_dictionary.h" + +CPDF_Pattern::CPDF_Pattern(CPDF_Document* pDoc, CPDF_Object* pObj, const CFX_Matrix& parentMatrix) - : m_PatternType(type), - m_pDocument(pDoc), - m_pPatternObj(pObj), - m_ParentMatrix(parentMatrix) {} + : m_pDocument(pDoc), m_pPatternObj(pObj), m_ParentMatrix(parentMatrix) {} CPDF_Pattern::~CPDF_Pattern() {} + +void CPDF_Pattern::SetPatternToFormMatrix() { + CPDF_Dictionary* pDict = pattern_obj()->GetDict(); + m_Pattern2Form = pDict->GetMatrixFor("Matrix"); + m_Pattern2Form.Concat(m_ParentMatrix); +} diff --git a/core/fpdfapi/page/cpdf_pattern.h b/core/fpdfapi/page/cpdf_pattern.h index d44965ff16..3b948aedb7 100644 --- a/core/fpdfapi/page/cpdf_pattern.h +++ b/core/fpdfapi/page/cpdf_pattern.h @@ -24,18 +24,20 @@ class CPDF_Pattern { virtual CPDF_TilingPattern* AsTilingPattern() = 0; virtual CPDF_ShadingPattern* AsShadingPattern() = 0; + // All the getters that return pointers return non-NULL pointers. CPDF_Document* document() { return m_pDocument; } CPDF_Object* pattern_obj() { return m_pPatternObj; } CFX_Matrix* pattern_to_form() { return &m_Pattern2Form; } const CFX_Matrix& parent_matrix() const { return m_ParentMatrix; } protected: - CPDF_Pattern(PatternType type, - CPDF_Document* pDoc, + CPDF_Pattern(CPDF_Document* pDoc, CPDF_Object* pObj, const CFX_Matrix& parentMatrix); - const PatternType m_PatternType; + void SetPatternToFormMatrix(); + + private: CPDF_Document* const m_pDocument; CPDF_Object* const m_pPatternObj; CFX_Matrix m_Pattern2Form; diff --git a/core/fpdfapi/page/cpdf_shadingpattern.cpp b/core/fpdfapi/page/cpdf_shadingpattern.cpp index 133d32ff3a..dae5ec356c 100644 --- a/core/fpdfapi/page/cpdf_shadingpattern.cpp +++ b/core/fpdfapi/page/cpdf_shadingpattern.cpp @@ -31,27 +31,23 @@ CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, CPDF_Object* pPatternObj, bool bShading, const CFX_Matrix& parentMatrix) - : CPDF_Pattern(SHADING, - pDoc, - bShading ? nullptr : pPatternObj, - parentMatrix), + : CPDF_Pattern(pDoc, bShading ? nullptr : pPatternObj, parentMatrix), m_ShadingType(kInvalidShading), m_bShadingObj(bShading), m_pShadingObj(pPatternObj), m_pCS(nullptr), m_pCountedCS(nullptr) { + assert(document()); if (!bShading) { - CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); - m_Pattern2Form = pDict->GetMatrixFor("Matrix"); - m_pShadingObj = pDict->GetDirectObjectFor("Shading"); - m_Pattern2Form.Concat(parentMatrix); + m_pShadingObj = pattern_obj()->GetDict()->GetDirectObjectFor("Shading"); + SetPatternToFormMatrix(); } } CPDF_ShadingPattern::~CPDF_ShadingPattern() { CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : nullptr; - if (pCS && m_pDocument) { - auto* pPageData = m_pDocument->GetPageData(); + if (pCS) { + auto* pPageData = document()->GetPageData(); if (pPageData) pPageData->ReleaseColorSpace(pCS->GetArray()); } @@ -89,7 +85,7 @@ bool CPDF_ShadingPattern::Load() { if (!pCSObj) return false; - CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); + CPDF_DocPageData* pDocPageData = document()->GetPageData(); m_pCS = pDocPageData->GetColorSpace(pCSObj, nullptr); if (m_pCS) m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray()); diff --git a/core/fpdfapi/page/cpdf_tilingpattern.cpp b/core/fpdfapi/page/cpdf_tilingpattern.cpp index a68b4423e5..65542a27b5 100644 --- a/core/fpdfapi/page/cpdf_tilingpattern.cpp +++ b/core/fpdfapi/page/cpdf_tilingpattern.cpp @@ -15,11 +15,10 @@ CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc, CPDF_Object* pPatternObj, const CFX_Matrix& parentMatrix) - : CPDF_Pattern(TILING, pDoc, pPatternObj, parentMatrix) { - CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); - m_Pattern2Form = pDict->GetMatrixFor("Matrix"); - m_bColored = pDict->GetIntegerFor("PaintType") == 1; - m_Pattern2Form.Concat(parentMatrix); + : CPDF_Pattern(pDoc, pPatternObj, parentMatrix) { + assert(document()); + m_bColored = pattern_obj()->GetDict()->GetIntegerFor("PaintType") == 1; + SetPatternToFormMatrix(); } CPDF_TilingPattern::~CPDF_TilingPattern() {} @@ -36,20 +35,21 @@ bool CPDF_TilingPattern::Load() { if (m_pForm) return true; - CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); + CPDF_Dictionary* pDict = pattern_obj()->GetDict(); if (!pDict) return false; m_bColored = pDict->GetIntegerFor("PaintType") == 1; - m_XStep = (float)fabs(pDict->GetNumberFor("XStep")); - m_YStep = (float)fabs(pDict->GetNumberFor("YStep")); + m_XStep = static_cast<float>(fabs(pDict->GetNumberFor("XStep"))); + m_YStep = static_cast<float>(fabs(pDict->GetNumberFor("YStep"))); - CPDF_Stream* pStream = m_pPatternObj->AsStream(); + CPDF_Stream* pStream = pattern_obj()->AsStream(); if (!pStream) return false; - m_pForm = pdfium::MakeUnique<CPDF_Form>(m_pDocument, nullptr, pStream); - m_pForm->ParseContent(nullptr, &m_ParentMatrix, nullptr); + const CFX_Matrix& matrix = parent_matrix(); + m_pForm = pdfium::MakeUnique<CPDF_Form>(document(), nullptr, pStream); + m_pForm->ParseContent(nullptr, &matrix, nullptr); m_BBox = pDict->GetRectFor("BBox"); return true; } |