| Index: core/fpdfapi/fpdf_page/fpdf_page_doc.cpp
|
| diff --git a/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp
|
| index f8729066747ba6f484dd32cd90bed6fccf5ea8c4..f0c5302b95a66ae0c28099e60d588b37ce474d45 100644
|
| --- a/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp
|
| +++ b/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp
|
| @@ -19,6 +19,7 @@
|
| #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
|
| #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h"
|
| #include "core/fpdfapi/include/cpdf_modulemgr.h"
|
| +#include "third_party/base/stl_util.h"
|
|
|
| void CPDF_ModuleMgr::InitPageModule() {
|
| m_pPageModule.reset(new CPDF_PageModule);
|
| @@ -222,17 +223,29 @@ void CPDF_DocPageData::ReleaseFont(CPDF_Dictionary* pFontDict) {
|
| CPDF_ColorSpace* CPDF_DocPageData::GetColorSpace(
|
| CPDF_Object* pCSObj,
|
| const CPDF_Dictionary* pResources) {
|
| + std::set<CPDF_Object*> visited;
|
| + return GetColorSpaceImpl(pCSObj, pResources, &visited);
|
| +}
|
| +
|
| +CPDF_ColorSpace* CPDF_DocPageData::GetColorSpaceImpl(
|
| + CPDF_Object* pCSObj,
|
| + const CPDF_Dictionary* pResources,
|
| + std::set<CPDF_Object*>* pVisited) {
|
| if (!pCSObj)
|
| return nullptr;
|
|
|
| + if (pdfium::ContainsKey(*pVisited, pCSObj))
|
| + return nullptr;
|
| +
|
| if (pCSObj->IsName()) {
|
| CFX_ByteString name = pCSObj->GetString();
|
| CPDF_ColorSpace* pCS = CPDF_ColorSpace::ColorspaceFromName(name);
|
| if (!pCS && pResources) {
|
| CPDF_Dictionary* pList = pResources->GetDictBy("ColorSpace");
|
| if (pList) {
|
| - pCSObj = pList->GetDirectObjectBy(name);
|
| - return GetColorSpace(pCSObj, nullptr);
|
| + pdfium::ScopedSetInsertion<CPDF_Object*> insertion(pVisited, pCSObj);
|
| + return GetColorSpaceImpl(pList->GetDirectObjectBy(name), nullptr,
|
| + pVisited);
|
| }
|
| }
|
| if (!pCS || !pResources)
|
| @@ -254,14 +267,22 @@ CPDF_ColorSpace* CPDF_DocPageData::GetColorSpace(
|
| pDefaultCS = pColorSpaces->GetDirectObjectBy("DefaultCMYK");
|
| break;
|
| }
|
| - return pDefaultCS ? GetColorSpace(pDefaultCS, nullptr) : pCS;
|
| + if (!pDefaultCS)
|
| + return pCS;
|
| +
|
| + pdfium::ScopedSetInsertion<CPDF_Object*> insertion(pVisited, pCSObj);
|
| + return GetColorSpaceImpl(pDefaultCS, nullptr, pVisited);
|
| }
|
|
|
| CPDF_Array* pArray = pCSObj->AsArray();
|
| if (!pArray || pArray->GetCount() == 0)
|
| return nullptr;
|
| - if (pArray->GetCount() == 1)
|
| - return GetColorSpace(pArray->GetDirectObjectAt(0), pResources);
|
| +
|
| + if (pArray->GetCount() == 1) {
|
| + pdfium::ScopedSetInsertion<CPDF_Object*> insertion(pVisited, pCSObj);
|
| + return GetColorSpaceImpl(pArray->GetDirectObjectAt(0), pResources,
|
| + pVisited);
|
| + }
|
|
|
| CPDF_CountedColorSpace* csData = nullptr;
|
| auto it = m_ColorSpaceMap.find(pCSObj);
|
|
|