diff options
author | Henrique Nakashima <hnakashima@chromium.org> | 2018-07-05 16:55:48 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-07-05 16:55:48 +0000 |
commit | 6c4ca9f597ae84550e0b8a4323e44b188f9bb274 (patch) | |
tree | 6f1cb0f180279e943d5e6ed463bfb17edf154bd8 | |
parent | 3fab31fb8e35eca693322ac292228e993b508102 (diff) | |
download | pdfium-6c4ca9f597ae84550e0b8a4323e44b188f9bb274.tar.xz |
Delete CPDF_ContentMark::HasRef()
This is called by many client to make sure CountItems() does not
crash. Moving the check to CountItems() makes HasRef() unnecessary.
Bug: pdfium:1037
Change-Id: I4f21f33a88c9aad54f0dae18a38b370c6ceaec80
Reviewed-on: https://pdfium-review.googlesource.com/37133
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
-rw-r--r-- | core/fpdfapi/page/cpdf_contentmark.cpp | 3 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_contentmark.h | 2 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_streamcontentparser.cpp | 6 | ||||
-rw-r--r-- | core/fpdfapi/render/cpdf_renderstatus.cpp | 9 | ||||
-rw-r--r-- | core/fpdftext/cpdf_textpage.cpp | 13 | ||||
-rw-r--r-- | fpdfsdk/fpdf_editpage.cpp | 5 |
6 files changed, 14 insertions, 24 deletions
diff --git a/core/fpdfapi/page/cpdf_contentmark.cpp b/core/fpdfapi/page/cpdf_contentmark.cpp index 77c29a53d7..a4bb15ed9a 100644 --- a/core/fpdfapi/page/cpdf_contentmark.cpp +++ b/core/fpdfapi/page/cpdf_contentmark.cpp @@ -23,6 +23,9 @@ std::unique_ptr<CPDF_ContentMark> CPDF_ContentMark::Clone() { } size_t CPDF_ContentMark::CountItems() const { + if (!m_Ref) + return 0; + return m_Ref->CountItems(); } diff --git a/core/fpdfapi/page/cpdf_contentmark.h b/core/fpdfapi/page/cpdf_contentmark.h index 241a0ffbf3..6012350398 100644 --- a/core/fpdfapi/page/cpdf_contentmark.h +++ b/core/fpdfapi/page/cpdf_contentmark.h @@ -29,8 +29,6 @@ class CPDF_ContentMark { void AddMark(ByteString name, const CPDF_Dictionary* pDict, bool bDirect); void DeleteLastMark(); - bool HasRef() const { return !!m_Ref; } - private: class MarkData : public Retainable { public: diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index b2ac553191..c698c52370 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -868,10 +868,8 @@ void CPDF_StreamContentParser::Handle_MarkPlace_Dictionary() {} void CPDF_StreamContentParser::Handle_EndImage() {} void CPDF_StreamContentParser::Handle_EndMarkedContent() { - if (m_pCurContentMark->HasRef()) { - m_pCurContentMark = m_pCurContentMark->Clone(); - m_pCurContentMark->DeleteLastMark(); - } + m_pCurContentMark = m_pCurContentMark->Clone(); + m_pCurContentMark->DeleteLastMark(); } void CPDF_StreamContentParser::Handle_EndText() { diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp index 29a30157df..433d32b886 100644 --- a/core/fpdfapi/render/cpdf_renderstatus.cpp +++ b/core/fpdfapi/render/cpdf_renderstatus.cpp @@ -1100,10 +1100,9 @@ void CPDF_RenderStatus::RenderSingleObject(CPDF_PageObject* pObj, return; } m_pCurObj = pObj; - if (m_Options.GetOCContext() && pObj->m_ContentMark.HasRef()) { - if (!m_Options.GetOCContext()->CheckObjectVisible(pObj)) { - return; - } + if (m_Options.GetOCContext() && + !m_Options.GetOCContext()->CheckObjectVisible(pObj)) { + return; } ProcessClipPath(pObj->m_ClipPath, pObj2Device); if (ProcessTransparency(pObj, pObj2Device)) { @@ -1129,7 +1128,7 @@ bool CPDF_RenderStatus::ContinueSingleObject(CPDF_PageObject* pObj, } m_pCurObj = pObj; - if (m_Options.GetOCContext() && pObj->m_ContentMark.HasRef() && + if (m_Options.GetOCContext() && !m_Options.GetOCContext()->CheckObjectVisible(pObj)) { return false; } diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp index 60e574558b..4c3196427a 100644 --- a/core/fpdftext/cpdf_textpage.cpp +++ b/core/fpdftext/cpdf_textpage.cpp @@ -838,9 +838,6 @@ void CPDF_TextPage::ProcessTextObject( FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) { CPDF_TextObject* pTextObj = Obj.m_pTextObj.Get(); - if (!pTextObj->m_ContentMark.HasRef()) - return FPDFText_MarkedContent::Pass; - size_t nContentMark = pTextObj->m_ContentMark.CountItems(); if (nContentMark == 0) return FPDFText_MarkedContent::Pass; @@ -864,7 +861,7 @@ FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) { if (m_pPreTextObj) { const CPDF_ContentMark& mark = m_pPreTextObj->m_ContentMark; - if (mark.HasRef() && mark.CountItems() == nContentMark && + if (mark.CountItems() == nContentMark && mark.GetItem(nContentMark - 1).GetParam() == pDict) { return FPDFText_MarkedContent::Done; } @@ -900,15 +897,13 @@ FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) { void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) { CPDF_TextObject* pTextObj = Obj.m_pTextObj.Get(); - if (!pTextObj->m_ContentMark.HasRef()) - return; - int nContentMark = pTextObj->m_ContentMark.CountItems(); - if (nContentMark < 1) + size_t nContentMark = pTextObj->m_ContentMark.CountItems(); + if (nContentMark == 0) return; WideString actText; - for (int n = 0; n < nContentMark; n++) { + for (size_t n = 0; n < nContentMark; n++) { const CPDF_ContentMarkItem& item = pTextObj->m_ContentMark.GetItem(n); const CPDF_Dictionary* pDict = item.GetParam(); if (pDict) diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp index 36853c70c6..d21b215d09 100644 --- a/fpdfsdk/fpdf_editpage.cpp +++ b/fpdfsdk/fpdf_editpage.cpp @@ -277,7 +277,7 @@ FPDFPageObj_CountMarks(FPDF_PAGEOBJECT page_object) { const auto& mark = CPDFPageObjectFromFPDFPageObject(page_object)->m_ContentMark; - return mark.HasRef() ? mark.CountItems() : 0; + return mark.CountItems(); } FPDF_EXPORT FPDF_PAGEOBJECTMARK FPDF_CALLCONV @@ -286,9 +286,6 @@ FPDFPageObj_GetMark(FPDF_PAGEOBJECT page_object, unsigned long index) { return nullptr; auto* mark = &CPDFPageObjectFromFPDFPageObject(page_object)->m_ContentMark; - if (!mark->HasRef()) - return nullptr; - if (index >= mark->CountItems()) return nullptr; |