Return retained references from CPDF_Dictionary::GetDictFor().

Change-Id: I6151eac16bb22ac92aa18084353a2d6e12a52c89
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/98191
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
index 7cc9e0c..87d723a 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
@@ -40,7 +40,7 @@
                                          const ByteString& type,
                                          const ByteString& name) {
     const CPDF_Dictionary* pResources = pGen->m_pObjHolder->GetResources();
-    return pResources->GetDictFor(type)->GetDictFor(name);
+    return pResources->GetDictFor(type)->GetDictFor(name).Get();
   }
 
   void TestProcessText(CPDF_PageContentGenerator* pGen,
@@ -373,7 +373,8 @@
   EXPECT_EQ("Font", fontDict->GetNameFor("Type"));
   EXPECT_EQ("TrueType", fontDict->GetNameFor("Subtype"));
   EXPECT_EQ("Helvetica", fontDict->GetNameFor("BaseFont"));
-  const CPDF_Dictionary* fontDesc = fontDict->GetDictFor("FontDescriptor");
+  RetainPtr<const CPDF_Dictionary> fontDesc =
+      fontDict->GetDictFor("FontDescriptor");
   ASSERT_TRUE(fontDesc);
   EXPECT_TRUE(fontDesc->GetObjNum());
   EXPECT_EQ("FontDescriptor", fontDesc->GetNameFor("Type"));
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp
index 9fa160a..9ef8796 100644
--- a/core/fpdfapi/font/cpdf_cidfont.cpp
+++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -450,13 +450,15 @@
     m_pCMap = pFontGlobals->GetPredefinedCMap(cmap);
   }
 
-  const CPDF_Dictionary* pFontDesc = pCIDFontDict->GetDictFor("FontDescriptor");
+  RetainPtr<const CPDF_Dictionary> pFontDesc =
+      pCIDFontDict->GetDictFor("FontDescriptor");
   if (pFontDesc)
-    LoadFontDescriptor(pFontDesc);
+    LoadFontDescriptor(pFontDesc.Get());
 
   m_Charset = m_pCMap->GetCharset();
   if (m_Charset == CIDSET_UNKNOWN) {
-    const CPDF_Dictionary* pCIDInfo = pCIDFontDict->GetDictFor("CIDSystemInfo");
+    RetainPtr<const CPDF_Dictionary> pCIDInfo =
+        pCIDFontDict->GetDictFor("CIDSystemInfo");
     if (pCIDInfo) {
       m_Charset = CPDF_CMapParser::CharsetFromOrdering(
           pCIDInfo->GetByteStringFor("Ordering").AsStringView());
@@ -868,9 +870,10 @@
   auto* pFontGlobals = CPDF_FontGlobals::GetInstance();
   m_pCMap = pFontGlobals->GetPredefinedCMap("GBK-EUC-H");
   m_pCID2UnicodeMap = pFontGlobals->GetCID2UnicodeMap(m_Charset);
-  const CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictFor("FontDescriptor");
+  RetainPtr<const CPDF_Dictionary> pFontDesc =
+      m_pFontDict->GetDictFor("FontDescriptor");
   if (pFontDesc)
-    LoadFontDescriptor(pFontDesc);
+    LoadFontDescriptor(pFontDesc.Get());
 
   if (!IsEmbedded())
     LoadSubstFont();
diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp
index 0aac03f..1e32c34 100644
--- a/core/fpdfapi/font/cpdf_font.cpp
+++ b/core/fpdfapi/font/cpdf_font.cpp
@@ -312,7 +312,7 @@
     ByteString tag = pFontDict->GetByteStringFor("BaseFont").First(4);
     for (size_t i = 0; i < std::size(kChineseFontNames); ++i) {
       if (tag == ByteString(kChineseFontNames[i], kChineseFontNameSize)) {
-        const CPDF_Dictionary* pFontDesc =
+        RetainPtr<const CPDF_Dictionary> pFontDesc =
             pFontDict->GetDictFor("FontDescriptor");
         if (!pFontDesc || !pFontDesc->KeyExist("FontFile2"))
           pFont = pdfium::MakeRetain<CPDF_CIDFont>(pDoc, std::move(pFontDict));
diff --git a/core/fpdfapi/font/cpdf_simplefont.cpp b/core/fpdfapi/font/cpdf_simplefont.cpp
index af10611..3f0eed6 100644
--- a/core/fpdfapi/font/cpdf_simplefont.cpp
+++ b/core/fpdfapi/font/cpdf_simplefont.cpp
@@ -221,10 +221,11 @@
 }
 
 bool CPDF_SimpleFont::LoadCommon() {
-  const CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictFor("FontDescriptor");
+  RetainPtr<const CPDF_Dictionary> pFontDesc =
+      m_pFontDict->GetDictFor("FontDescriptor");
   if (pFontDesc)
-    LoadFontDescriptor(pFontDesc);
-  LoadCharWidths(pFontDesc);
+    LoadFontDescriptor(pFontDesc.Get());
+  LoadCharWidths(pFontDesc.Get());
   if (m_pFontFile) {
     if (m_BaseFontName.GetLength() > 8 && m_BaseFontName[7] == '+')
       m_BaseFontName = m_BaseFontName.Last(m_BaseFontName.GetLength() - 8);
diff --git a/core/fpdfapi/font/cpdf_type1font.cpp b/core/fpdfapi/font/cpdf_type1font.cpp
index 0bbe416..2bdbf48 100644
--- a/core/fpdfapi/font/cpdf_type1font.cpp
+++ b/core/fpdfapi/font/cpdf_type1font.cpp
@@ -90,7 +90,8 @@
   if (!IsBase14Font())
     return LoadCommon();
 
-  const CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictFor("FontDescriptor");
+  RetainPtr<const CPDF_Dictionary> pFontDesc =
+      m_pFontDict->GetDictFor("FontDescriptor");
   if (pFontDesc && pFontDesc->KeyExist("Flags")) {
     m_Flags = pFontDesc->GetIntegerFor("Flags");
   } else if (IsSymbolicFont()) {
diff --git a/core/fpdfapi/page/cpdf_contentmarkitem.cpp b/core/fpdfapi/page/cpdf_contentmarkitem.cpp
index 1fa177c..08a8be4 100644
--- a/core/fpdfapi/page/cpdf_contentmarkitem.cpp
+++ b/core/fpdfapi/page/cpdf_contentmarkitem.cpp
@@ -15,10 +15,11 @@
 
 CPDF_ContentMarkItem::~CPDF_ContentMarkItem() = default;
 
+// TODO(tsepez): return retained reference.
 const CPDF_Dictionary* CPDF_ContentMarkItem::GetParam() const {
   switch (m_ParamType) {
     case kPropertiesDict:
-      return m_pPropertiesHolder->GetDictFor(m_PropertyName);
+      return m_pPropertiesHolder->GetDictFor(m_PropertyName).Get();
     case kDirectDict:
       return m_pDirectDict.Get();
     case kNone:
diff --git a/core/fpdfapi/page/cpdf_docpagedata.cpp b/core/fpdfapi/page/cpdf_docpagedata.cpp
index f4c428d..bd17bb6 100644
--- a/core/fpdfapi/page/cpdf_docpagedata.cpp
+++ b/core/fpdfapi/page/cpdf_docpagedata.cpp
@@ -272,7 +272,8 @@
     ByteString name = pCSObj->GetString();
     RetainPtr<CPDF_ColorSpace> pCS = CPDF_ColorSpace::GetStockCSForName(name);
     if (!pCS && pResources) {
-      const CPDF_Dictionary* pList = pResources->GetDictFor("ColorSpace");
+      RetainPtr<const CPDF_Dictionary> pList =
+          pResources->GetDictFor("ColorSpace");
       if (pList) {
         return GetColorSpaceInternal(pList->GetDirectObjectFor(name).Get(),
                                      nullptr, pVisited, pVisitedInternal);
@@ -281,7 +282,8 @@
     if (!pCS || !pResources)
       return pCS;
 
-    const CPDF_Dictionary* pColorSpaces = pResources->GetDictFor("ColorSpace");
+    RetainPtr<const CPDF_Dictionary> pColorSpaces =
+        pResources->GetDictFor("ColorSpace");
     if (!pColorSpaces)
       return pCS;
 
diff --git a/core/fpdfapi/page/cpdf_occontext.cpp b/core/fpdfapi/page/cpdf_occontext.cpp
index efcf167..e4c2949 100644
--- a/core/fpdfapi/page/cpdf_occontext.cpp
+++ b/core/fpdfapi/page/cpdf_occontext.cpp
@@ -34,10 +34,11 @@
   return bsIntent == "All" || bsIntent == csElement;
 }
 
+// TODO(tsepez): return retained object.
 const CPDF_Dictionary* GetConfig(CPDF_Document* pDoc,
                                  const CPDF_Dictionary* pOCGDict) {
   DCHECK(pOCGDict);
-  const CPDF_Dictionary* pOCProperties =
+  RetainPtr<const CPDF_Dictionary> pOCProperties =
       pDoc->GetRoot()->GetDictFor("OCProperties");
   if (!pOCProperties)
     return nullptr;
@@ -49,17 +50,17 @@
   if (!pOCGs->Contains(pOCGDict))
     return nullptr;
 
-  const CPDF_Dictionary* pConfig = pOCProperties->GetDictFor("D");
+  RetainPtr<const CPDF_Dictionary> pConfig = pOCProperties->GetDictFor("D");
   RetainPtr<const CPDF_Array> pConfigs = pOCProperties->GetArrayFor("Configs");
   if (!pConfigs)
-    return pConfig;
+    return pConfig.Get();
 
   for (size_t i = 0; i < pConfigs->size(); i++) {
     RetainPtr<const CPDF_Dictionary> pFind = pConfigs->GetDictAt(i);
     if (pFind && HasIntent(pFind.Get(), "View", ""))
       return pFind.Get();
   }
-  return pConfig;
+  return pConfig.Get();
 }
 
 ByteString GetUsageTypeString(CPDF_OCContext::UsageType eType) {
@@ -126,7 +127,7 @@
     if (!pOCGs->Contains(pOCGDict))
       continue;
 
-    const CPDF_Dictionary* pState = pUsage->GetDictFor(csConfig);
+    RetainPtr<const CPDF_Dictionary> pState = pUsage->GetDictFor(csConfig);
     if (!pState)
       continue;
 
@@ -140,9 +141,9 @@
     return true;
 
   ByteString csState = GetUsageTypeString(m_eUsageType);
-  const CPDF_Dictionary* pUsage = pOCGDict->GetDictFor("Usage");
+  RetainPtr<const CPDF_Dictionary> pUsage = pOCGDict->GetDictFor("Usage");
   if (pUsage) {
-    const CPDF_Dictionary* pState = pUsage->GetDictFor(csState);
+    RetainPtr<const CPDF_Dictionary> pState = pUsage->GetDictFor(csState);
     if (pState) {
       ByteString csFind = csState + "State";
       if (pState->KeyExist(csFind))
diff --git a/core/fpdfapi/page/cpdf_page.cpp b/core/fpdfapi/page/cpdf_page.cpp
index 63eb328..9e06c13 100644
--- a/core/fpdfapi/page/cpdf_page.cpp
+++ b/core/fpdfapi/page/cpdf_page.cpp
@@ -88,7 +88,7 @@
       return pObj.Get();
     }
     visited.insert(pPageDict);
-    pPageDict = pPageDict->GetDictFor(pdfium::page_object::kParent);
+    pPageDict = pPageDict->GetDictFor(pdfium::page_object::kParent).Get();
   }
   return nullptr;
 }
diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.cpp b/core/fpdfapi/page/cpdf_pageobjectholder.cpp
index 7e9ab5a..02fe84a 100644
--- a/core/fpdfapi/page/cpdf_pageobjectholder.cpp
+++ b/core/fpdfapi/page/cpdf_pageobjectholder.cpp
@@ -114,7 +114,7 @@
 }
 
 void CPDF_PageObjectHolder::LoadTransparencyInfo() {
-  const CPDF_Dictionary* pGroup = m_pDict->GetDictFor("Group");
+  RetainPtr<const CPDF_Dictionary> pGroup = m_pDict->GetDictFor("Group");
   if (!pGroup)
     return;
 
diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
index 83291b8..f928cfb 100644
--- a/core/fpdfapi/page/cpdf_streamparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamparser.cpp
@@ -151,7 +151,7 @@
         pParam = pParams->GetDictAt(0);
     } else {
       decoder = pFilter->GetString();
-      pParam.Reset(pDict->GetDictFor(pdfium::stream::kDecodeParms));
+      pParam = pDict->GetDictFor(pdfium::stream::kDecodeParms);
     }
   }
   uint32_t width = pDict->GetIntegerFor("Width");
diff --git a/core/fpdfapi/parser/cpdf_dictionary.cpp b/core/fpdfapi/parser/cpdf_dictionary.cpp
index 33f814b..cba8091 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.cpp
+++ b/core/fpdfapi/parser/cpdf_dictionary.cpp
@@ -166,9 +166,9 @@
   return nullptr;
 }
 
-const CPDF_Dictionary* CPDF_Dictionary::GetDictFor(
+RetainPtr<const CPDF_Dictionary> CPDF_Dictionary::GetDictFor(
     const ByteString& key) const {
-  return GetDictForInternal(key);
+  return pdfium::WrapRetain(GetDictForInternal(key));
 }
 
 RetainPtr<CPDF_Dictionary> CPDF_Dictionary::GetMutableDictFor(
diff --git a/core/fpdfapi/parser/cpdf_dictionary.h b/core/fpdfapi/parser/cpdf_dictionary.h
index e0e3e5d..b6f6b02 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.h
+++ b/core/fpdfapi/parser/cpdf_dictionary.h
@@ -66,7 +66,7 @@
   int GetIntegerFor(const ByteString& key, int default_int) const;
   int GetDirectIntegerFor(const ByteString& key) const;
   float GetFloatFor(const ByteString& key) const;
-  const CPDF_Dictionary* GetDictFor(const ByteString& key) const;
+  RetainPtr<const CPDF_Dictionary> GetDictFor(const ByteString& key) const;
   RetainPtr<CPDF_Dictionary> GetMutableDictFor(const ByteString& key);
   RetainPtr<CPDF_Dictionary> GetOrCreateDictFor(const ByteString& key);
   RetainPtr<const CPDF_Array> GetArrayFor(const ByteString& key) const;
diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp
index 59e6f71..1ed98c1 100644
--- a/core/fpdfapi/parser/cpdf_document.cpp
+++ b/core/fpdfapi/parser/cpdf_document.cpp
@@ -268,9 +268,10 @@
   return error;
 }
 
+// TODO(tsepez): return retained references.
 const CPDF_Dictionary* CPDF_Document::GetPagesDict() const {
   const CPDF_Dictionary* pRoot = GetRoot();
-  return pRoot ? pRoot->GetDictFor("Pages") : nullptr;
+  return pRoot ? pRoot->GetDictFor("Pages").Get() : nullptr;
 }
 
 CPDF_Dictionary* CPDF_Document::GetPagesDict() {
diff --git a/core/fpdfapi/parser/cpdf_security_handler.cpp b/core/fpdfapi/parser/cpdf_security_handler.cpp
index ce934b9..6701687 100644
--- a/core/fpdfapi/parser/cpdf_security_handler.cpp
+++ b/core/fpdfapi/parser/cpdf_security_handler.cpp
@@ -234,14 +234,16 @@
   *keylen_out = 0;
   int keylen = 0;
   if (Version >= 4) {
-    const CPDF_Dictionary* pCryptFilters = pEncryptDict->GetDictFor("CF");
+    RetainPtr<const CPDF_Dictionary> pCryptFilters =
+        pEncryptDict->GetDictFor("CF");
     if (!pCryptFilters)
       return false;
 
     if (name == "Identity") {
       *cipher = CPDF_CryptoHandler::Cipher::kNone;
     } else {
-      const CPDF_Dictionary* pDefFilter = pCryptFilters->GetDictFor(name);
+      RetainPtr<const CPDF_Dictionary> pDefFilter =
+          pCryptFilters->GetDictFor(name);
       if (!pDefFilter)
         return false;
 
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 4d8a67c..1f0d987 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -375,8 +375,8 @@
                          res)) {
     return;
   }
+  RetainPtr<const CPDF_Dictionary> pFormResource;
   CFX_Matrix matrix = mtObj2Device * buffer.GetMatrix();
-  const CPDF_Dictionary* pFormResource = nullptr;
   const CPDF_FormObject* pFormObj = pObj->AsForm();
   if (pFormObj)
     pFormResource = pFormObj->form()->GetDict()->GetDictFor("Resources");
@@ -385,7 +385,7 @@
   status.SetDeviceMatrix(buffer.GetMatrix());
   status.SetTransparency(m_Transparency);
   status.SetDropObjects(m_bDropObjects);
-  status.SetFormResource(pFormResource);
+  status.SetFormResource(pFormResource.Get());
   status.Initialize(nullptr, nullptr);
   status.RenderSingleObject(pObj, matrix);
   buffer.OutputToDevice();
@@ -396,20 +396,21 @@
 #if defined(_SKIA_SUPPORT_)
   DebugVerifyDeviceIsPreMultiplied();
 #endif
-  const CPDF_Dictionary* pOC = pFormObj->form()->GetDict()->GetDictFor("OC");
+  RetainPtr<const CPDF_Dictionary> pOC =
+      pFormObj->form()->GetDict()->GetDictFor("OC");
   if (pOC && m_Options.GetOCContext() &&
-      !m_Options.GetOCContext()->CheckOCGVisible(pOC)) {
+      !m_Options.GetOCContext()->CheckOCGVisible(pOC.Get())) {
     return true;
   }
   CFX_Matrix matrix = pFormObj->form_matrix() * mtObj2Device;
-  const CPDF_Dictionary* pResources =
+  RetainPtr<const CPDF_Dictionary> pResources =
       pFormObj->form()->GetDict()->GetDictFor("Resources");
   CPDF_RenderStatus status(m_pContext.Get(), m_pDevice);
   status.SetOptions(m_Options);
   status.SetStopObject(m_pStopObj.Get());
   status.SetTransparency(m_Transparency);
   status.SetDropObjects(m_bDropObjects);
-  status.SetFormResource(pResources);
+  status.SetFormResource(pResources.Get());
   status.Initialize(this, pFormObj);
   status.m_curBlend = m_curBlend;
   {
@@ -630,7 +631,7 @@
       pSMaskDict = nullptr;
     }
   }
-  const CPDF_Dictionary* pFormResource = nullptr;
+  RetainPtr<const CPDF_Dictionary> pFormResource;
   float group_alpha = 1.0f;
   CPDF_Transparency transparency = m_Transparency;
   bool bGroupTransparent = false;
@@ -717,7 +718,7 @@
   bitmap_render.SetStopObject(m_pStopObj.Get());
   bitmap_render.SetStdCS(true);
   bitmap_render.SetDropObjects(m_bDropObjects);
-  bitmap_render.SetFormResource(pFormResource);
+  bitmap_render.SetFormResource(pFormResource.Get());
   bitmap_render.Initialize(nullptr, nullptr);
   bitmap_render.ProcessObjectNoClip(pPageObj, new_matrix);
 #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
@@ -991,7 +992,7 @@
       options.GetOptions().bRectAA = true;
 
       const auto* pForm = static_cast<const CPDF_Form*>(pType3Char->form());
-      const CPDF_Dictionary* pFormResource =
+      RetainPtr<const CPDF_Dictionary> pFormResource =
           pForm->GetDict()->GetDictFor("Resources");
 
       if (fill_alpha == 255) {
@@ -1001,7 +1002,7 @@
         status.SetType3Char(pType3Char);
         status.SetFillColor(fill_argb);
         status.SetDropObjects(m_bDropObjects);
-        status.SetFormResource(pFormResource);
+        status.SetFormResource(pFormResource.Get());
         status.Initialize(this, pStates.get());
         status.m_Type3FontCache = m_Type3FontCache;
         status.m_Type3FontCache.emplace_back(pType3Font);
@@ -1026,7 +1027,7 @@
         status.SetType3Char(pType3Char);
         status.SetFillColor(fill_argb);
         status.SetDropObjects(m_bDropObjects);
-        status.SetFormResource(pFormResource);
+        status.SetFormResource(pFormResource.Get());
         status.Initialize(this, pStates.get());
         status.m_Type3FontCache = m_Type3FontCache;
         status.m_Type3FontCache.emplace_back(pType3Font);
@@ -1436,7 +1437,7 @@
     bitmap->Clear(0);
   }
 
-  const CPDF_Dictionary* pFormResource =
+  RetainPtr<const CPDF_Dictionary> pFormResource =
       form.GetDict()->GetDictFor("Resources");
   CPDF_RenderOptions options;
   options.SetColorMode(bLuminosity ? CPDF_RenderOptions::kNormal
@@ -1446,7 +1447,7 @@
   status.SetGroupFamily(nCSFamily);
   status.SetLoadMask(bLuminosity);
   status.SetStdCS(true);
-  status.SetFormResource(pFormResource);
+  status.SetFormResource(pFormResource.Get());
   status.SetDropObjects(m_bDropObjects);
   status.Initialize(nullptr, nullptr);
   status.RenderObjectList(&form, matrix);
@@ -1502,7 +1503,7 @@
     return kDefaultColor;
 
   RetainPtr<const CPDF_Object> pCSObj;
-  const CPDF_Dictionary* pGroup =
+  RetainPtr<const CPDF_Dictionary> pGroup =
       pGroupDict ? pGroupDict->GetDictFor("Group") : nullptr;
   if (pGroup)
     pCSObj = pGroup->GetDirectObjectFor(pdfium::transparency::kCS);
diff --git a/core/fpdfapi/render/cpdf_rendertiling.cpp b/core/fpdfapi/render/cpdf_rendertiling.cpp
index 160c384..957a7d1 100644
--- a/core/fpdfapi/render/cpdf_rendertiling.cpp
+++ b/core/fpdfapi/render/cpdf_rendertiling.cpp
@@ -124,7 +124,8 @@
       pStates = CPDF_RenderStatus::CloneObjStates(pPageObj, bStroke);
 
     const CPDF_Dictionary* pFormDict = pPatternForm->GetDict();
-    const CPDF_Dictionary* pFormResource = pFormDict->GetDictFor("Resources");
+    RetainPtr<const CPDF_Dictionary> pFormResource =
+        pFormDict->GetDictFor("Resources");
     for (int col = min_col; col <= max_col; col++) {
       for (int row = min_row; row <= max_row; row++) {
         CFX_PointF original = mtPattern2Device.Transform(
@@ -136,7 +137,7 @@
         CPDF_RenderStatus status(pContext, pDevice);
         status.SetOptions(options);
         status.SetTransparency(pPatternForm->GetTransparency());
-        status.SetFormResource(pFormResource);
+        status.SetFormResource(pFormResource.Get());
         status.SetDropObjects(pRenderStatus->GetDropObjects());
         status.Initialize(pRenderStatus, pStates.get());
         status.RenderObjectList(pPatternForm, matrix);
diff --git a/core/fpdfdoc/cpdf_aaction.cpp b/core/fpdfdoc/cpdf_aaction.cpp
index 3c9535a..ae0563a 100644
--- a/core/fpdfdoc/cpdf_aaction.cpp
+++ b/core/fpdfdoc/cpdf_aaction.cpp
@@ -54,7 +54,9 @@
 }
 
 CPDF_Action CPDF_AAction::GetAction(AActionType eType) const {
-  return CPDF_Action(m_pDict ? m_pDict->GetDictFor(kAATypes[eType]) : nullptr);
+  // TOOD(tsepez): pass retained object.
+  return CPDF_Action(m_pDict ? m_pDict->GetDictFor(kAATypes[eType]).Get()
+                             : nullptr);
 }
 
 // static
diff --git a/core/fpdfdoc/cpdf_action.cpp b/core/fpdfdoc/cpdf_action.cpp
index 469243b..010658b 100644
--- a/core/fpdfdoc/cpdf_action.cpp
+++ b/core/fpdfdoc/cpdf_action.cpp
@@ -74,7 +74,7 @@
   if (type != Type::kLaunch)
     return WideString();
 
-  const CPDF_Dictionary* pWinDict = m_pDict->GetDictFor("Win");
+  RetainPtr<const CPDF_Dictionary> pWinDict = m_pDict->GetDictFor("Win");
   if (!pWinDict)
     return WideString();
 
@@ -88,7 +88,7 @@
 
   ByteString csURI = m_pDict->GetByteStringFor("URI");
   const CPDF_Dictionary* pRoot = pDoc->GetRoot();
-  const CPDF_Dictionary* pURI = pRoot->GetDictFor("URI");
+  RetainPtr<const CPDF_Dictionary> pURI = pRoot->GetDictFor("URI");
   if (pURI) {
     auto result = csURI.Find(":");
     if (!result.has_value() || result.value() == 0) {
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp
index 472f709..e046947 100644
--- a/core/fpdfdoc/cpdf_annot.cpp
+++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -89,7 +89,8 @@
   if (as.IsEmpty()) {
     ByteString value = pAnnotDict->GetByteStringFor("V");
     if (value.IsEmpty()) {
-      const CPDF_Dictionary* pParentDict = pAnnotDict->GetDictFor("Parent");
+      RetainPtr<const CPDF_Dictionary> pParentDict =
+          pAnnotDict->GetDictFor("Parent");
       value = pParentDict ? pParentDict->GetByteStringFor("V") : ByteString();
     }
     as = (!value.IsEmpty() && pDict->KeyExist(value)) ? value : "Off";
@@ -129,7 +130,7 @@
 bool CPDF_Annot::ShouldGenerateAP() const {
   // If AP dictionary exists and defines an appearance for normal mode, we use
   // the appearance defined in the existing AP dictionary.
-  const CPDF_Dictionary* pAP =
+  RetainPtr<const CPDF_Dictionary> pAP =
       m_pAnnotDict->GetDictFor(pdfium::annotation::kAP);
   if (pAP && pAP->GetDictFor("N"))
     return false;
@@ -446,7 +447,7 @@
   if (!bPrinting && (annot_flags & pdfium::annotation_flags::kNoView)) {
     return;
   }
-  const CPDF_Dictionary* pBS = m_pAnnotDict->GetDictFor("BS");
+  RetainPtr<const CPDF_Dictionary> pBS = m_pAnnotDict->GetDictFor("BS");
   char style_char;
   float width;
   RetainPtr<const CPDF_Array> pDashArray;
diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp
index cff51be..2cbbc91 100644
--- a/core/fpdfdoc/cpdf_annotlist.cpp
+++ b/core/fpdfdoc/cpdf_annotlist.cpp
@@ -157,7 +157,7 @@
   if (pAnnotDict->KeyExist(pdfium::annotation::kAS))
     return;
 
-  const CPDF_Dictionary* pParentDict =
+  RetainPtr<const CPDF_Dictionary> pParentDict =
       pAnnotDict->GetDictFor(pdfium::form_fields::kParent);
   if (!pParentDict || !pParentDict->KeyExist(pdfium::annotation::kAS))
     return;
@@ -177,7 +177,7 @@
     return;
 
   const CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
-  const CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm");
+  RetainPtr<const CPDF_Dictionary> pAcroForm = pRoot->GetDictFor("AcroForm");
   bool bRegenerateAP =
       pAcroForm && pAcroForm->GetBooleanFor("NeedAppearances", false);
   for (size_t i = 0; i < pAnnots->size(); ++i) {
diff --git a/core/fpdfdoc/cpdf_apsettings.cpp b/core/fpdfdoc/cpdf_apsettings.cpp
index 039708d..9b9bd34 100644
--- a/core/fpdfdoc/cpdf_apsettings.cpp
+++ b/core/fpdfdoc/cpdf_apsettings.cpp
@@ -106,7 +106,8 @@
 }
 
 CPDF_IconFit CPDF_ApSettings::GetIconFit() const {
-  return CPDF_IconFit(m_pDict ? m_pDict->GetDictFor("IF") : nullptr);
+  // TODO(tsepez): pass retained object.
+  return CPDF_IconFit(m_pDict ? m_pDict->GetDictFor("IF").Get() : nullptr);
 }
 
 int CPDF_ApSettings::GetTextPosition() const {
diff --git a/core/fpdfdoc/cpdf_bafontmap.cpp b/core/fpdfdoc/cpdf_bafontmap.cpp
index 8e7ad2f..4c851ba 100644
--- a/core/fpdfdoc/cpdf_bafontmap.cpp
+++ b/core/fpdfdoc/cpdf_bafontmap.cpp
@@ -180,15 +180,16 @@
   if (!pRootDict)
     return nullptr;
 
-  const CPDF_Dictionary* pAcroFormDict = pRootDict->GetDictFor("AcroForm");
+  RetainPtr<const CPDF_Dictionary> pAcroFormDict =
+      pRootDict->GetDictFor("AcroForm");
   if (!pAcroFormDict)
     return nullptr;
 
-  const CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictFor("DR");
+  RetainPtr<const CPDF_Dictionary> pDRDict = pAcroFormDict->GetDictFor("DR");
   if (!pDRDict)
     return nullptr;
 
-  return FindResFontSameCharset(pDRDict, sFontAlias, nCharset);
+  return FindResFontSameCharset(pDRDict.Get(), sFontAlias, nCharset);
 }
 
 RetainPtr<CPDF_Font> CPDF_BAFontMap::FindResFontSameCharset(
@@ -198,7 +199,7 @@
   if (!pResDict)
     return nullptr;
 
-  const CPDF_Dictionary* pFonts = pResDict->GetDictFor("Font");
+  RetainPtr<const CPDF_Dictionary> pFonts = pResDict->GetDictFor("Font");
   if (!pFonts)
     return nullptr;
 
diff --git a/core/fpdfdoc/cpdf_bookmark.cpp b/core/fpdfdoc/cpdf_bookmark.cpp
index 41d8ef9..6d0a1a6 100644
--- a/core/fpdfdoc/cpdf_bookmark.cpp
+++ b/core/fpdfdoc/cpdf_bookmark.cpp
@@ -48,7 +48,8 @@
 }
 
 CPDF_Action CPDF_Bookmark::GetAction() const {
-  return CPDF_Action(m_pDict ? m_pDict->GetDictFor("A") : nullptr);
+  // TODO(tsepez): pass retained object.
+  return CPDF_Action(m_pDict ? m_pDict->GetDictFor("A").Get() : nullptr);
 }
 
 int CPDF_Bookmark::GetCount() const {
diff --git a/core/fpdfdoc/cpdf_bookmarktree.cpp b/core/fpdfdoc/cpdf_bookmarktree.cpp
index b92f9bd..8f3ac78 100644
--- a/core/fpdfdoc/cpdf_bookmarktree.cpp
+++ b/core/fpdfdoc/cpdf_bookmarktree.cpp
@@ -17,15 +17,16 @@
 CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild(
     const CPDF_Bookmark& parent) const {
   const CPDF_Dictionary* parent_dict = parent.GetDict();
-  if (parent_dict)
-    return CPDF_Bookmark(parent_dict->GetDictFor("First"));
-
+  if (parent_dict) {
+    // TODO(tsepez): pass retained argument.
+    return CPDF_Bookmark(parent_dict->GetDictFor("First").Get());
+  }
   const CPDF_Dictionary* root = document_->GetRoot();
   if (!root)
     return CPDF_Bookmark();
 
-  const CPDF_Dictionary* outlines = root->GetDictFor("Outlines");
-  return outlines ? CPDF_Bookmark(outlines->GetDictFor("First"))
+  RetainPtr<const CPDF_Dictionary> outlines = root->GetDictFor("Outlines");
+  return outlines ? CPDF_Bookmark(outlines->GetDictFor("First").Get())
                   : CPDF_Bookmark();
 }
 
@@ -35,6 +36,6 @@
   if (!dict)
     return CPDF_Bookmark();
 
-  const CPDF_Dictionary* next = dict->GetDictFor("Next");
-  return next != dict ? CPDF_Bookmark(next) : CPDF_Bookmark();
+  RetainPtr<const CPDF_Dictionary> next = dict->GetDictFor("Next");
+  return next != dict ? CPDF_Bookmark(next.Get()) : CPDF_Bookmark();
 }
diff --git a/core/fpdfdoc/cpdf_filespec.cpp b/core/fpdfdoc/cpdf_filespec.cpp
index 16779de..66de713 100644
--- a/core/fpdfdoc/cpdf_filespec.cpp
+++ b/core/fpdfdoc/cpdf_filespec.cpp
@@ -131,7 +131,7 @@
     return nullptr;
 
   // Get the embedded files dictionary.
-  const CPDF_Dictionary* pFiles = pDict->GetDictFor("EF");
+  RetainPtr<const CPDF_Dictionary> pFiles = pDict->GetDictFor("EF");
   if (!pFiles)
     return nullptr;
 
@@ -157,6 +157,7 @@
       static_cast<const CPDF_FileSpec*>(this)->GetFileStream());
 }
 
+// TODO(tsepez): return retained reference.
 const CPDF_Dictionary* CPDF_FileSpec::GetParamsDict() const {
   const CPDF_Stream* pStream = GetFileStream();
   if (!pStream)
@@ -164,7 +165,7 @@
 
   // TODO(tsepez): return retained reference.
   RetainPtr<const CPDF_Dictionary> pDict = pStream->GetDict();
-  return pDict ? pDict->GetDictFor("Params") : nullptr;
+  return pDict ? pDict->GetDictFor("Params").Get() : nullptr;
 }
 
 CPDF_Dictionary* CPDF_FileSpec::GetParamsDict() {
diff --git a/core/fpdfdoc/cpdf_formcontrol.cpp b/core/fpdfdoc/cpdf_formcontrol.cpp
index ab90199..80a1f1e 100644
--- a/core/fpdfdoc/cpdf_formcontrol.cpp
+++ b/core/fpdfdoc/cpdf_formcontrol.cpp
@@ -56,11 +56,11 @@
 ByteString CPDF_FormControl::GetOnStateName() const {
   DCHECK(GetType() == CPDF_FormField::kCheckBox ||
          GetType() == CPDF_FormField::kRadioButton);
-  const CPDF_Dictionary* pAP = m_pWidgetDict->GetDictFor("AP");
+  RetainPtr<const CPDF_Dictionary> pAP = m_pWidgetDict->GetDictFor("AP");
   if (!pAP)
     return ByteString();
 
-  const CPDF_Dictionary* pN = pAP->GetDictFor("N");
+  RetainPtr<const CPDF_Dictionary> pN = pAP->GetDictFor("N");
   if (!pN)
     return ByteString();
 
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index 4fad26e..26c9530 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -45,7 +45,8 @@
     return pAttr;
 
   return GetFieldAttrRecursive(
-      pFieldDict->GetDictFor(pdfium::form_fields::kParent), name, nLevel + 1);
+      pFieldDict->GetDictFor(pdfium::form_fields::kParent).Get(), name,
+      nLevel + 1);
 }
 
 }  // namespace
@@ -88,7 +89,7 @@
       else
         full_name = short_name + L'.' + full_name;
     }
-    pLevel = pLevel->GetDictFor(pdfium::form_fields::kParent);
+    pLevel = pLevel->GetDictFor(pdfium::form_fields::kParent).Get();
     if (pdfium::Contains(visited, pLevel))
       break;
   }
diff --git a/core/fpdfdoc/cpdf_generateap.cpp b/core/fpdfdoc/cpdf_generateap.cpp
index afa5973..87b622e 100644
--- a/core/fpdfdoc/cpdf_generateap.cpp
+++ b/core/fpdfdoc/cpdf_generateap.cpp
@@ -320,7 +320,7 @@
 }
 
 float GetBorderWidth(const CPDF_Dictionary* pDict) {
-  const CPDF_Dictionary* pBorderStyleDict = pDict->GetDictFor("BS");
+  RetainPtr<const CPDF_Dictionary> pBorderStyleDict = pDict->GetDictFor("BS");
   if (pBorderStyleDict && pBorderStyleDict->KeyExist("W"))
     return pBorderStyleDict->GetFloatFor("W");
 
@@ -332,7 +332,7 @@
 }
 
 RetainPtr<const CPDF_Array> GetDashArray(const CPDF_Dictionary* pDict) {
-  const CPDF_Dictionary* pBorderStyleDict = pDict->GetDictFor("BS");
+  RetainPtr<const CPDF_Dictionary> pBorderStyleDict = pDict->GetDictFor("BS");
   if (pBorderStyleDict && pBorderStyleDict->GetByteStringFor("S") == "D")
     return pBorderStyleDict->GetArrayFor("D");
 
@@ -959,7 +959,7 @@
     return;
 
   CFX_FloatRect rcAnnot = pAnnotDict->GetRectFor(pdfium::annotation::kRect);
-  const CPDF_Dictionary* pMKDict = pAnnotDict->GetDictFor("MK");
+  RetainPtr<const CPDF_Dictionary> pMKDict = pAnnotDict->GetDictFor("MK");
   int32_t nRotate =
       pMKDict ? pMKDict->GetIntegerFor(pdfium::appearance::kR) : 0;
 
@@ -993,7 +993,7 @@
   CPVT_Dash dsBorder(3, 0, 0);
   CFX_Color crLeftTop;
   CFX_Color crRightBottom;
-  if (const CPDF_Dictionary* pBSDict = pAnnotDict->GetDictFor("BS")) {
+  if (RetainPtr<const CPDF_Dictionary> pBSDict = pAnnotDict->GetDictFor("BS")) {
     if (pBSDict->KeyExist("W"))
       fBorderWidth = pBSDict->GetFloatFor("W");
 
diff --git a/core/fpdfdoc/cpdf_interactiveform.cpp b/core/fpdfdoc/cpdf_interactiveform.cpp
index 7cbaa9a..3df2f07 100644
--- a/core/fpdfdoc/cpdf_interactiveform.cpp
+++ b/core/fpdfdoc/cpdf_interactiveform.cpp
@@ -131,7 +131,7 @@
     m++;
   }
 
-  const CPDF_Dictionary* pDict = pResDict->GetDictFor("Font");
+  RetainPtr<const CPDF_Dictionary> pDict = pResDict->GetDictFor("Font");
   DCHECK(pDict);
 
   int num = 0;
@@ -174,15 +174,16 @@
 bool FindFont(const CPDF_Dictionary* pFormDict,
               const CPDF_Font* pFont,
               ByteString* csNameTag) {
-  const CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR");
+  RetainPtr<const CPDF_Dictionary> pDR = pFormDict->GetDictFor("DR");
   if (!pDR)
     return false;
 
-  const CPDF_Dictionary* pFonts = pDR->GetDictFor("Font");
-  if (!ValidateFontResourceDict(pFonts))
+  RetainPtr<const CPDF_Dictionary> pFonts = pDR->GetDictFor("Font");
+  // TODO(tsepez): this eventually locks the dict, pass locker instead.
+  if (!ValidateFontResourceDict(pFonts.Get()))
     return false;
 
-  CPDF_DictionaryLocker locker(pFonts);
+  CPDF_DictionaryLocker locker(std::move(pFonts));
   for (const auto& it : locker) {
     const ByteString& csKey = it.first;
     RetainPtr<const CPDF_Dictionary> pElement =
@@ -205,12 +206,12 @@
   if (csFontName.IsEmpty())
     return false;
 
-  const CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR");
+  RetainPtr<const CPDF_Dictionary> pDR = pFormDict->GetDictFor("DR");
   if (!pDR)
     return false;
 
-  const CPDF_Dictionary* pFonts = pDR->GetDictFor("Font");
-  if (!ValidateFontResourceDict(pFonts))
+  RetainPtr<const CPDF_Dictionary> pFonts = pDR->GetDictFor("Font");
+  if (!ValidateFontResourceDict(pFonts.Get()))
     return false;
 
   csFontName.Remove(' ');
@@ -299,12 +300,12 @@
                                    CPDF_Document* pDocument,
                                    FX_Charset charSet,
                                    ByteString* csNameTag) {
-  const CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR");
+  RetainPtr<const CPDF_Dictionary> pDR = pFormDict->GetDictFor("DR");
   if (!pDR)
     return nullptr;
 
-  const CPDF_Dictionary* pFonts = pDR->GetDictFor("Font");
-  if (!ValidateFontResourceDict(pFonts))
+  RetainPtr<const CPDF_Dictionary> pFonts = pDR->GetDictFor("Font");
+  if (!ValidateFontResourceDict(pFonts.Get()))
     return nullptr;
 
   CPDF_DictionaryLocker locker(pFonts);
@@ -800,7 +801,7 @@
     RetainPtr<CPDF_Dictionary> pFieldDict) {
   if (!pFieldDict->KeyExist(pdfium::form_fields::kFT)) {
     // Key "FT" is required for terminal fields, it is also inheritable.
-    const CPDF_Dictionary* pParentDict =
+    RetainPtr<const CPDF_Dictionary> pParentDict =
         pFieldDict->GetDictFor(pdfium::form_fields::kParent);
     if (!pParentDict || !pParentDict->KeyExist(pdfium::form_fields::kFT))
       return;
diff --git a/core/fpdfdoc/cpdf_link.cpp b/core/fpdfdoc/cpdf_link.cpp
index 24d1a5d..ac349de 100644
--- a/core/fpdfdoc/cpdf_link.cpp
+++ b/core/fpdfdoc/cpdf_link.cpp
@@ -25,5 +25,5 @@
 }
 
 CPDF_Action CPDF_Link::GetAction() {
-  return CPDF_Action(m_pDict->GetDictFor("A"));
+  return CPDF_Action(m_pDict->GetDictFor("A").Get());
 }
diff --git a/core/fpdfdoc/cpdf_nametree.cpp b/core/fpdfdoc/cpdf_nametree.cpp
index a2860b0..e5590ee 100644
--- a/core/fpdfdoc/cpdf_nametree.cpp
+++ b/core/fpdfdoc/cpdf_nametree.cpp
@@ -397,7 +397,8 @@
 
 RetainPtr<const CPDF_Array> LookupOldStyleNamedDest(CPDF_Document* pDoc,
                                                     const ByteString& name) {
-  const CPDF_Dictionary* pDests = pDoc->GetRoot()->GetDictFor("Dests");
+  RetainPtr<const CPDF_Dictionary> pDests =
+      pDoc->GetRoot()->GetDictFor("Dests");
   if (!pDests)
     return nullptr;
   return GetNamedDestFromObject(pDests->GetDirectObjectFor(name));
diff --git a/core/fpdfdoc/cpdf_pagelabel.cpp b/core/fpdfdoc/cpdf_pagelabel.cpp
index 98e0388..e67aee6 100644
--- a/core/fpdfdoc/cpdf_pagelabel.cpp
+++ b/core/fpdfdoc/cpdf_pagelabel.cpp
@@ -90,11 +90,12 @@
   if (!pPDFRoot)
     return absl::nullopt;
 
-  const CPDF_Dictionary* pLabels = pPDFRoot->GetDictFor("PageLabels");
+  RetainPtr<const CPDF_Dictionary> pLabels = pPDFRoot->GetDictFor("PageLabels");
   if (!pLabels)
     return absl::nullopt;
 
-  CPDF_NumberTree numberTree(pLabels);
+  // TODO(tsepez): pass retained object.
+  CPDF_NumberTree numberTree(pLabels.Get());
   RetainPtr<const CPDF_Object> pValue;
   int n = nPage;
   while (n >= 0) {
diff --git a/core/fpdfdoc/cpdf_structtree.cpp b/core/fpdfdoc/cpdf_structtree.cpp
index d68a074..8650e65 100644
--- a/core/fpdfdoc/cpdf_structtree.cpp
+++ b/core/fpdfdoc/cpdf_structtree.cpp
@@ -19,7 +19,7 @@
 
 bool IsTagged(const CPDF_Document* pDoc) {
   const CPDF_Dictionary* pCatalog = pDoc->GetRoot();
-  const CPDF_Dictionary* pMarkInfo = pCatalog->GetDictFor("MarkInfo");
+  RetainPtr<const CPDF_Dictionary> pMarkInfo = pCatalog->GetDictFor("MarkInfo");
   return pMarkInfo && pMarkInfo->GetIntegerFor("Marked");
 }
 
@@ -62,11 +62,13 @@
 
   m_Kids.clear();
   m_Kids.resize(dwKids);
-  const CPDF_Dictionary* pParentTree = m_pTreeRoot->GetDictFor("ParentTree");
+  RetainPtr<const CPDF_Dictionary> pParentTree =
+      m_pTreeRoot->GetDictFor("ParentTree");
   if (!pParentTree)
     return;
 
-  CPDF_NumberTree parent_tree(pParentTree);
+  // TODO(tsepez): pass retained object.
+  CPDF_NumberTree parent_tree(pParentTree.Get());
   int parents_id = pPageDict->GetIntegerFor("StructParents", -1);
   if (parents_id < 0)
     return;
@@ -99,7 +101,7 @@
 
   auto pElement = pdfium::MakeRetain<CPDF_StructElement>(this, pDict);
   (*map)[pDict] = pElement;
-  const CPDF_Dictionary* pParent = pDict->GetDictFor("P");
+  RetainPtr<const CPDF_Dictionary> pParent = pDict->GetDictFor("P");
   if (!pParent || pParent->GetNameFor("Type") == "StructTreeRoot") {
     if (!AddTopLevelNode(pDict, pElement))
       map->erase(pDict);
@@ -107,7 +109,7 @@
   }
 
   RetainPtr<CPDF_StructElement> pParentElement =
-      AddPageNode(pParent, map, nLevel + 1);
+      AddPageNode(pParent.Get(), map, nLevel + 1);
   if (!pParentElement)
     return pElement;
 
diff --git a/core/fpdfdoc/cpdf_viewerpreferences.cpp b/core/fpdfdoc/cpdf_viewerpreferences.cpp
index 19d0780..fcb65f9 100644
--- a/core/fpdfdoc/cpdf_viewerpreferences.cpp
+++ b/core/fpdfdoc/cpdf_viewerpreferences.cpp
@@ -55,7 +55,8 @@
   return pName->GetString();
 }
 
+// TODO(tsepez): return retained object.
 const CPDF_Dictionary* CPDF_ViewerPreferences::GetViewerPreferences() const {
   const CPDF_Dictionary* pDict = m_pDoc->GetRoot();
-  return pDict ? pDict->GetDictFor("ViewerPreferences") : nullptr;
+  return pDict ? pDict->GetDictFor("ViewerPreferences").Get() : nullptr;
 }
diff --git a/fpdfsdk/cpdfsdk_appstream.cpp b/fpdfsdk/cpdfsdk_appstream.cpp
index 0cd0d47..7cf03dd 100644
--- a/fpdfsdk/cpdfsdk_appstream.cpp
+++ b/fpdfsdk/cpdfsdk_appstream.cpp
@@ -1859,7 +1859,7 @@
     pStreamDict->SetNewFor<CPDF_Number>("FormType", 1);
 
     if (pOrigStreamDict) {
-      const CPDF_Dictionary* pResources =
+      RetainPtr<const CPDF_Dictionary> pResources =
           pOrigStreamDict->GetDictFor("Resources");
       if (pResources)
         pStreamDict->SetFor("Resources", pResources->Clone());
diff --git a/fpdfsdk/cpdfsdk_baannot.cpp b/fpdfsdk/cpdfsdk_baannot.cpp
index dbc32a4..7e912a0 100644
--- a/fpdfsdk/cpdfsdk_baannot.cpp
+++ b/fpdfsdk/cpdfsdk_baannot.cpp
@@ -137,7 +137,7 @@
   if (pBorder)
     return pBorder->GetIntegerAt(2);
 
-  const CPDF_Dictionary* pBSDict = GetAnnotDict()->GetDictFor("BS");
+  RetainPtr<const CPDF_Dictionary> pBSDict = GetAnnotDict()->GetDictFor("BS");
   if (pBSDict)
     return pBSDict->GetIntegerFor("W", 1);
 
@@ -171,7 +171,7 @@
 }
 
 BorderStyle CPDFSDK_BAAnnot::GetBorderStyle() const {
-  const CPDF_Dictionary* pBSDict = GetAnnotDict()->GetDictFor("BS");
+  RetainPtr<const CPDF_Dictionary> pBSDict = GetAnnotDict()->GetDictFor("BS");
   if (pBSDict) {
     ByteString sBorderStyle = pBSDict->GetByteStringFor("S", "S");
     if (sBorderStyle == "S")
@@ -207,11 +207,12 @@
 }
 
 CPDF_Action CPDFSDK_BAAnnot::GetAction() const {
-  return CPDF_Action(GetAnnotDict()->GetDictFor("A"));
+  return CPDF_Action(GetAnnotDict()->GetDictFor("A").Get());
 }
 
 CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const {
-  return CPDF_AAction(GetAnnotDict()->GetDictFor(pdfium::form_fields::kAA));
+  return CPDF_AAction(
+      GetAnnotDict()->GetDictFor(pdfium::form_fields::kAA).Get());
 }
 
 CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) {
diff --git a/fpdfsdk/cpdfsdk_helpers.cpp b/fpdfsdk/cpdfsdk_helpers.cpp
index 762cfc3..c066fe7 100644
--- a/fpdfsdk/cpdfsdk_helpers.cpp
+++ b/fpdfsdk/cpdfsdk_helpers.cpp
@@ -49,7 +49,7 @@
   if (!root)
     return false;
 
-  const CPDF_Dictionary* form = root->GetDictFor("AcroForm");
+  RetainPtr<const CPDF_Dictionary> form = root->GetDictFor("AcroForm");
   return form && form->GetArrayFor("XFA");
 }
 
@@ -358,12 +358,13 @@
   if (pRootDict->KeyExist("Collection"))
     RaiseUnsupportedError(FPDF_UNSP_DOC_PORTABLECOLLECTION);
 
-  const CPDF_Dictionary* pNameDict = pRootDict->GetDictFor("Names");
+  RetainPtr<const CPDF_Dictionary> pNameDict = pRootDict->GetDictFor("Names");
   if (pNameDict) {
     if (pNameDict->KeyExist("EmbeddedFiles"))
       RaiseUnsupportedError(FPDF_UNSP_DOC_ATTACHMENT);
 
-    const CPDF_Dictionary* pJSDict = pNameDict->GetDictFor("JavaScript");
+    RetainPtr<const CPDF_Dictionary> pJSDict =
+        pNameDict->GetDictFor("JavaScript");
     if (pJSDict) {
       RetainPtr<const CPDF_Array> pArray = pJSDict->GetArrayFor("Names");
       if (pArray) {
diff --git a/fpdfsdk/cpdfsdk_interactiveform.cpp b/fpdfsdk/cpdfsdk_interactiveform.cpp
index 700b352..e1d8c74 100644
--- a/fpdfsdk/cpdfsdk_interactiveform.cpp
+++ b/fpdfsdk/cpdfsdk_interactiveform.cpp
@@ -77,7 +77,8 @@
   if (!pFDF)
     return buffer;
 
-  const CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictFor("FDF");
+  RetainPtr<const CPDF_Dictionary> pMainDict =
+      pFDF->GetRoot()->GetDictFor("FDF");
   if (!pMainDict)
     return ByteString();
 
@@ -132,7 +133,8 @@
   CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument();
   CPDFSDK_PageView* pPage = nullptr;
 
-  if (const CPDF_Dictionary* pPageDict = pControlDict->GetDictFor("P")) {
+  if (RetainPtr<const CPDF_Dictionary> pPageDict =
+          pControlDict->GetDictFor("P")) {
     int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum());
     if (nPageIndex >= 0)
       pPage = m_pFormFillEnv->GetPageViewAtIndex(nPageIndex);
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index cc6df3f..6b80ffe 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -342,7 +342,7 @@
 #endif  // PDF_ENABLE_XFA
 
 bool CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode) {
-  const CPDF_Dictionary* pAP =
+  RetainPtr<const CPDF_Dictionary> pAP =
       GetAnnotDict()->GetDictFor(pdfium::annotation::kAP);
   if (!pAP)
     return false;
diff --git a/fpdfsdk/fpdf_annot_embeddertest.cpp b/fpdfsdk/fpdf_annot_embeddertest.cpp
index fa7a14a..0328f39 100644
--- a/fpdfsdk/fpdf_annot_embeddertest.cpp
+++ b/fpdfsdk/fpdf_annot_embeddertest.cpp
@@ -139,13 +139,14 @@
   ASSERT_TRUE(context);
   const CPDF_Dictionary* annot_dict = context->GetAnnotDict();
   ASSERT_TRUE(annot_dict);
-  const CPDF_Dictionary* ap_dict =
+  RetainPtr<const CPDF_Dictionary> ap_dict =
       annot_dict->GetDictFor(pdfium::annotation::kAP);
   ASSERT_TRUE(ap_dict);
-  const CPDF_Dictionary* stream_dict = ap_dict->GetDictFor("N");
+  RetainPtr<const CPDF_Dictionary> stream_dict = ap_dict->GetDictFor("N");
   ASSERT_TRUE(stream_dict);
   // Check for non-existence of resources dictionary in case of opaque color
-  const CPDF_Dictionary* resources_dict = stream_dict->GetDictFor("Resources");
+  RetainPtr<const CPDF_Dictionary> resources_dict =
+      stream_dict->GetDictFor("Resources");
   ASSERT_FALSE(resources_dict);
   ByteString type = stream_dict->GetByteStringFor(pdfium::annotation::kType);
   EXPECT_EQ("XObject", type);
@@ -189,17 +190,18 @@
   ASSERT_TRUE(context);
   const CPDF_Dictionary* annot_dict = context->GetAnnotDict();
   ASSERT_TRUE(annot_dict);
-  const CPDF_Dictionary* ap_dict =
+  RetainPtr<const CPDF_Dictionary> ap_dict =
       annot_dict->GetDictFor(pdfium::annotation::kAP);
   ASSERT_TRUE(ap_dict);
-  const CPDF_Dictionary* stream_dict = ap_dict->GetDictFor("N");
+  RetainPtr<const CPDF_Dictionary> stream_dict = ap_dict->GetDictFor("N");
   ASSERT_TRUE(stream_dict);
-  const CPDF_Dictionary* resources_dict = stream_dict->GetDictFor("Resources");
+  RetainPtr<const CPDF_Dictionary> resources_dict =
+      stream_dict->GetDictFor("Resources");
   ASSERT_TRUE(stream_dict);
-  const CPDF_Dictionary* extGState_dict =
+  RetainPtr<const CPDF_Dictionary> extGState_dict =
       resources_dict->GetDictFor("ExtGState");
   ASSERT_TRUE(extGState_dict);
-  const CPDF_Dictionary* gs_dict = extGState_dict->GetDictFor("GS");
+  RetainPtr<const CPDF_Dictionary> gs_dict = extGState_dict->GetDictFor("GS");
   ASSERT_TRUE(gs_dict);
   ByteString type = gs_dict->GetByteStringFor(pdfium::annotation::kType);
   EXPECT_EQ("ExtGState", type);
diff --git a/fpdfsdk/fpdf_catalog.cpp b/fpdfsdk/fpdf_catalog.cpp
index 97bddde..58fcd7c 100644
--- a/fpdfsdk/fpdf_catalog.cpp
+++ b/fpdfsdk/fpdf_catalog.cpp
@@ -18,6 +18,6 @@
   if (!pCatalog)
     return false;
 
-  const CPDF_Dictionary* pMarkInfo = pCatalog->GetDictFor("MarkInfo");
+  RetainPtr<const CPDF_Dictionary> pMarkInfo = pCatalog->GetDictFor("MarkInfo");
   return pMarkInfo && pMarkInfo->GetIntegerFor("Marked") != 0;
 }
diff --git a/fpdfsdk/fpdf_doc.cpp b/fpdfsdk/fpdf_doc.cpp
index 8ba87dd..c7c6499 100644
--- a/fpdfsdk/fpdf_doc.cpp
+++ b/fpdfsdk/fpdf_doc.cpp
@@ -440,7 +440,7 @@
     return nullptr;
 
   const CPDF_Dictionary* page_dict = pdf_page->GetDict();
-  CPDF_AAction aa(page_dict->GetDictFor(pdfium::form_fields::kAA));
+  CPDF_AAction aa(page_dict->GetDictFor(pdfium::form_fields::kAA).Get());
 
   CPDF_AAction::AActionType type;
   if (aa_type == FPDFPAGE_AACTION_OPEN)
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp
index 7029c38..f782ea9 100644
--- a/fpdfsdk/fpdf_edit_embeddertest.cpp
+++ b/fpdfsdk/fpdf_edit_embeddertest.cpp
@@ -98,7 +98,8 @@
                            bool bold,
                            bool italic,
                            pdfium::span<const uint8_t> span) {
-    const CPDF_Dictionary* font_desc = font_dict->GetDictFor("FontDescriptor");
+    RetainPtr<const CPDF_Dictionary> font_desc =
+        font_dict->GetDictFor("FontDescriptor");
     ASSERT_TRUE(font_desc);
     EXPECT_EQ("FontDescriptor", font_desc->GetNameFor("Type"));
     ByteString font_name = font_desc->GetNameFor("FontName");
@@ -2826,7 +2827,7 @@
 
   // Check that the ExtGState was created
   CPDF_Page* cpage = CPDFPageFromFPDFPage(page.get());
-  const CPDF_Dictionary* graphics_dict =
+  RetainPtr<const CPDF_Dictionary> graphics_dict =
       cpage->GetResources()->GetDictFor("ExtGState");
   ASSERT_TRUE(graphics_dict);
   EXPECT_EQ(2u, graphics_dict->size());
@@ -2880,7 +2881,7 @@
 
   // Check the ExtGState
   CPDF_Page* cpage = CPDFPageFromFPDFPage(page);
-  const CPDF_Dictionary* graphics_dict =
+  RetainPtr<const CPDF_Dictionary> graphics_dict =
       cpage->GetResources()->GetDictFor("ExtGState");
   ASSERT_TRUE(graphics_dict);
   EXPECT_EQ(2u, graphics_dict->size());
@@ -2922,7 +2923,8 @@
   FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 300, 300);
   FPDFPage_InsertObject(page, text_object);
   EXPECT_TRUE(FPDFPage_GenerateContent(page));
-  const CPDF_Dictionary* font_dict = cpage->GetResources()->GetDictFor("Font");
+  RetainPtr<const CPDF_Dictionary> font_dict =
+      cpage->GetResources()->GetDictFor("Font");
   ASSERT_TRUE(font_dict);
   EXPECT_EQ(1u, font_dict->size());
 
@@ -3020,7 +3022,7 @@
   EXPECT_EQ("Font", cidfont_dict->GetNameFor("Type"));
   EXPECT_EQ("CIDFontType0", cidfont_dict->GetNameFor("Subtype"));
   EXPECT_EQ("Tinos-Regular", cidfont_dict->GetNameFor("BaseFont"));
-  const CPDF_Dictionary* cidinfo_dict =
+  RetainPtr<const CPDF_Dictionary> cidinfo_dict =
       cidfont_dict->GetDictFor("CIDSystemInfo");
   ASSERT_TRUE(cidinfo_dict);
   RetainPtr<const CPDF_Object> registry =
@@ -3071,7 +3073,7 @@
   EXPECT_EQ("Font", cidfont_dict->GetNameFor("Type"));
   EXPECT_EQ("CIDFontType2", cidfont_dict->GetNameFor("Subtype"));
   EXPECT_EQ("Arimo-Italic", cidfont_dict->GetNameFor("BaseFont"));
-  const CPDF_Dictionary* cidinfo_dict =
+  RetainPtr<const CPDF_Dictionary> cidinfo_dict =
       cidfont_dict->GetDictFor("CIDSystemInfo");
   ASSERT_TRUE(cidinfo_dict);
   EXPECT_EQ("Adobe", cidinfo_dict->GetByteStringFor("Registry"));
diff --git a/fpdfsdk/fpdf_formfill.cpp b/fpdfsdk/fpdf_formfill.cpp
index 2694f75..04e500c 100644
--- a/fpdfsdk/fpdf_formfill.cpp
+++ b/fpdfsdk/fpdf_formfill.cpp
@@ -778,7 +778,7 @@
   if (!pDict)
     return;
 
-  CPDF_AAction aa(pDict->GetDictFor(pdfium::form_fields::kAA));
+  CPDF_AAction aa(pDict->GetDictFor(pdfium::form_fields::kAA).Get());
   auto type = static_cast<CPDF_AAction::AActionType>(aaType);
   if (aa.ActionExist(type))
     pFormFillEnv->DoActionDocument(aa.GetAction(type), type);
@@ -801,7 +801,7 @@
     return;
 
   const CPDF_Dictionary* pPageDict = pPDFPage->GetDict();
-  CPDF_AAction aa(pPageDict->GetDictFor(pdfium::form_fields::kAA));
+  CPDF_AAction aa(pPageDict->GetDictFor(pdfium::form_fields::kAA).Get());
   CPDF_AAction::AActionType type = aaType == FPDFPAGE_AACTION_OPEN
                                        ? CPDF_AAction::kOpenPage
                                        : CPDF_AAction::kClosePage;
diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp
index 68489a4..8ba338e 100644
--- a/fpdfsdk/fpdf_ppo.cpp
+++ b/fpdfsdk/fpdf_ppo.cpp
@@ -832,14 +832,15 @@
     return false;
 
   const CPDF_Dictionary* pSrcDict = pSrcDoc->GetRoot();
-  pSrcDict = pSrcDict->GetDictFor("ViewerPreferences");
-  if (!pSrcDict)
+  RetainPtr<const CPDF_Dictionary> pPrefDict =
+      pSrcDict->GetDictFor("ViewerPreferences");
+  if (!pPrefDict)
     return false;
 
   RetainPtr<CPDF_Dictionary> pDstDict = pDstDoc->GetMutableRoot();
   if (!pDstDict)
     return false;
 
-  pDstDict->SetFor("ViewerPreferences", pSrcDict->CloneDirectObject());
+  pDstDict->SetFor("ViewerPreferences", pPrefDict->CloneDirectObject());
   return true;
 }
diff --git a/fpdfsdk/fpdf_signature.cpp b/fpdfsdk/fpdf_signature.cpp
index aeb7c56..be1e0ac 100644
--- a/fpdfsdk/fpdf_signature.cpp
+++ b/fpdfsdk/fpdf_signature.cpp
@@ -22,7 +22,7 @@
   if (!root)
     return signatures;
 
-  const CPDF_Dictionary* acro_form = root->GetDictFor("AcroForm");
+  RetainPtr<const CPDF_Dictionary> acro_form = root->GetDictFor("AcroForm");
   if (!acro_form)
     return signatures;
 
@@ -71,7 +71,7 @@
   if (!signature_dict)
     return 0;
 
-  const CPDF_Dictionary* value_dict = signature_dict->GetDictFor("V");
+  RetainPtr<const CPDF_Dictionary> value_dict = signature_dict->GetDictFor("V");
   if (!value_dict)
     return 0;
 
@@ -93,7 +93,7 @@
   if (!signature_dict)
     return 0;
 
-  const CPDF_Dictionary* value_dict = signature_dict->GetDictFor("V");
+  RetainPtr<const CPDF_Dictionary> value_dict = signature_dict->GetDictFor("V");
   if (!value_dict)
     return 0;
 
@@ -119,7 +119,7 @@
   if (!signature_dict)
     return 0;
 
-  const CPDF_Dictionary* value_dict = signature_dict->GetDictFor("V");
+  RetainPtr<const CPDF_Dictionary> value_dict = signature_dict->GetDictFor("V");
   if (!value_dict || !value_dict->KeyExist("SubFilter"))
     return 0;
 
@@ -136,7 +136,7 @@
   if (!signature_dict)
     return 0;
 
-  const CPDF_Dictionary* value_dict = signature_dict->GetDictFor("V");
+  RetainPtr<const CPDF_Dictionary> value_dict = signature_dict->GetDictFor("V");
   if (!value_dict)
     return 0;
 
@@ -157,7 +157,7 @@
   if (!signature_dict)
     return 0;
 
-  const CPDF_Dictionary* value_dict = signature_dict->GetDictFor("V");
+  RetainPtr<const CPDF_Dictionary> value_dict = signature_dict->GetDictFor("V");
   if (!value_dict)
     return 0;
 
@@ -176,7 +176,7 @@
   if (!signature_dict)
     return permission;
 
-  const CPDF_Dictionary* value_dict = signature_dict->GetDictFor("V");
+  RetainPtr<const CPDF_Dictionary> value_dict = signature_dict->GetDictFor("V");
   if (!value_dict)
     return permission;
 
@@ -186,7 +186,7 @@
 
   CPDF_ArrayLocker locker(std::move(references));
   for (auto& reference : locker) {
-    const CPDF_Dictionary* reference_dict = reference->GetDict().Get();
+    RetainPtr<const CPDF_Dictionary> reference_dict = reference->GetDict();
     if (!reference_dict)
       continue;
 
@@ -194,7 +194,7 @@
     if (transform_method != "DocMDP")
       continue;
 
-    const CPDF_Dictionary* transform_params =
+    RetainPtr<const CPDF_Dictionary> transform_params =
         reference_dict->GetDictFor("TransformParams");
     if (!transform_params)
       continue;
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp
index f274512..8e5413c 100644
--- a/fpdfsdk/fpdf_transformpage.cpp
+++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -250,12 +250,12 @@
   }
 
   // Need to transform the patterns as well.
-  const CPDF_Dictionary* pRes =
+  RetainPtr<const CPDF_Dictionary> pRes =
       pPageDict->GetDictFor(pdfium::page_object::kResources);
   if (!pRes)
     return true;
 
-  const CPDF_Dictionary* pPatternDict = pRes->GetDictFor("Pattern");
+  RetainPtr<const CPDF_Dictionary> pPatternDict = pRes->GetDictFor("Pattern");
   if (!pPatternDict)
     return true;
 
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index 97a4a03..4c653af 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -106,7 +106,7 @@
     return nullptr;
 
   // TODO(tsepez): return retained objects.
-  const CPDF_Dictionary* acro_form = root->GetDictFor("AcroForm");
+  RetainPtr<const CPDF_Dictionary> acro_form = root->GetDictFor("AcroForm");
   return acro_form ? acro_form->GetObjectFor("XFA").Get() : nullptr;
 }
 
@@ -249,7 +249,7 @@
   if (!pRoot)
     return FORMTYPE_NONE;
 
-  const CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm");
+  RetainPtr<const CPDF_Dictionary> pAcroForm = pRoot->GetDictFor("AcroForm");
   if (!pAcroForm)
     return FORMTYPE_NONE;
 
@@ -1031,7 +1031,7 @@
 
   auto name_tree = CPDF_NameTree::Create(pDoc, "Dests");
   FX_SAFE_UINT32 count = name_tree ? name_tree->GetCount() : 0;
-  const CPDF_Dictionary* pOldStyleDests = pRoot->GetDictFor("Dests");
+  RetainPtr<const CPDF_Dictionary> pOldStyleDests = pRoot->GetDictFor("Dests");
   if (pOldStyleDests)
     count += pOldStyleDests->size();
   return count.ValueOrDefault(0);
@@ -1139,7 +1139,7 @@
   if (static_cast<size_t>(index) >= name_tree_count) {
     // If |index| is out of bounds, then try to retrieve the Nth old style named
     // destination. Where N is 0-indexed, with N = index - name_tree_count.
-    const CPDF_Dictionary* pDest = pRoot->GetDictFor("Dests");
+    RetainPtr<const CPDF_Dictionary> pDest = pRoot->GetDictFor("Dests");
     if (!pDest)
       return nullptr;
 
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
index eb768cf..cadb7aa 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
@@ -63,7 +63,7 @@
   if (!pRoot)
     return nullptr;
 
-  const CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm");
+  RetainPtr<const CPDF_Dictionary> pAcroForm = pRoot->GetDictFor("AcroForm");
   if (!pAcroForm)
     return nullptr;
 
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index bcdeb43..7f2d1fa 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -460,7 +460,7 @@
     if (!pRoot)
       return;
 
-    const CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm");
+    RetainPtr<const CPDF_Dictionary> pAcroForm = pRoot->GetDictFor("AcroForm");
     if (!pAcroForm)
       return;
 
@@ -750,7 +750,7 @@
     return false;
   }
 
-  const CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm");
+  RetainPtr<const CPDF_Dictionary> pAcroForm = pRoot->GetDictFor("AcroForm");
   if (!pAcroForm) {
     fileStream->Flush();
     return false;
diff --git a/xfa/fgas/font/cfgas_pdffontmgr.cpp b/xfa/fgas/font/cfgas_pdffontmgr.cpp
index 4d180c5..c572b8e 100644
--- a/xfa/fgas/font/cfgas_pdffontmgr.cpp
+++ b/xfa/fgas/font/cfgas_pdffontmgr.cpp
@@ -41,7 +41,7 @@
                                                    bool bBold,
                                                    bool bItalic,
                                                    bool bStrictMatch) {
-  const CPDF_Dictionary* pFontSetDict =
+  RetainPtr<const CPDF_Dictionary> pFontSetDict =
       m_pDoc->GetRoot()->GetDictFor("AcroForm")->GetDictFor("DR");
   if (!pFontSetDict)
     return nullptr;