Add truly const versions of CPDF_Document getters.

Instead of only having CPDF_Dictionary* GetRoot() const, provide
const CPDF_Dictionary* GetRoot() const and CPDF_Dictionary* GetRoot().
Do the same for GetInfo().

Change-Id: I6eae1208d38327fcdc7d0cd75069a01c95f4a92a
Reviewed-on: https://pdfium-review.googlesource.com/11671
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
diff --git a/core/fpdfapi/edit/cpdf_creator.cpp b/core/fpdfapi/edit/cpdf_creator.cpp
index 9735460..4c25f37 100644
--- a/core/fpdfapi/edit/cpdf_creator.cpp
+++ b/core/fpdfapi/edit/cpdf_creator.cpp
@@ -407,7 +407,7 @@
     if (m_bSecurityChanged && IsOriginal())
       m_dwFlags &= ~FPDFCREATE_INCREMENTAL;
 
-    CPDF_Dictionary* pDict = m_pDocument->GetRoot();
+    const CPDF_Dictionary* pDict = m_pDocument->GetRoot();
     m_pMetadata = pDict ? pDict->GetDirectObjectFor("Metadata") : nullptr;
     m_iStage = 10;
   }
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp
index c9cb1d7..76190fa 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.cpp
+++ b/core/fpdfapi/parser/cpdf_data_avail.cpp
@@ -431,7 +431,7 @@
 }
 
 bool CPDF_DataAvail::PreparePageItem() {
-  CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
+  const CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
   CPDF_Reference* pRef =
       ToReference(pRoot ? pRoot->GetObjectFor("Pages") : nullptr);
   if (!pRef) {
@@ -1486,7 +1486,7 @@
   }
 
   if (!m_bLinearizedFormParamLoad) {
-    CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
+    const CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
     if (!pRoot)
       return FormAvailable;
 
@@ -1520,7 +1520,7 @@
 }
 
 bool CPDF_DataAvail::ValidateForm() {
-  CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
+  const CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
   if (!pRoot)
     return true;
   CPDF_Object* pAcroForm = pRoot->GetObjectFor("AcroForm");
diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp
index 6aedc09..4715517 100644
--- a/core/fpdfapi/parser/cpdf_document.cpp
+++ b/core/fpdfapi/parser/cpdf_document.cpp
@@ -342,7 +342,6 @@
     : CPDF_IndirectObjectHolder(),
       m_pParser(std::move(pParser)),
       m_pRootDict(nullptr),
-      m_pInfoDict(nullptr),
       m_iNextPageToTraverse(0),
       m_bReachedMaxPageLevel(false),
       m_bLinearized(false),
@@ -474,7 +473,7 @@
 }
 
 CPDF_Dictionary* CPDF_Document::GetPagesDict() const {
-  CPDF_Dictionary* pRoot = GetRoot();
+  const CPDF_Dictionary* pRoot = GetRoot();
   return pRoot ? pRoot->GetDictFor("Pages") : nullptr;
 }
 
@@ -518,7 +517,7 @@
                                  uint32_t* skip_count,
                                  uint32_t objnum,
                                  int* index,
-                                 int level) {
+                                 int level) const {
   if (!pNode->KeyExist("Kids")) {
     if (objnum == pNode->GetObjNum())
       return *index;
@@ -654,7 +653,8 @@
 }
 
 void CPDF_Document::CreateNewDoc() {
-  ASSERT(!m_pRootDict && !m_pInfoDict);
+  ASSERT(!m_pRootDict);
+  ASSERT(!m_pInfoDict);
   m_pRootDict = NewIndirect<CPDF_Dictionary>();
   m_pRootDict->SetNewFor<CPDF_Name>("Type", "Catalog");
 
@@ -725,7 +725,7 @@
 }
 
 bool CPDF_Document::InsertNewPage(int iPage, CPDF_Dictionary* pPageDict) {
-  CPDF_Dictionary* pRoot = GetRoot();
+  const CPDF_Dictionary* pRoot = GetRoot();
   CPDF_Dictionary* pPages = pRoot ? pRoot->GetDictFor("Pages") : nullptr;
   if (!pPages)
     return false;
diff --git a/core/fpdfapi/parser/cpdf_document.h b/core/fpdfapi/parser/cpdf_document.h
index e6107e1..87d40fd 100644
--- a/core/fpdfapi/parser/cpdf_document.h
+++ b/core/fpdfapi/parser/cpdf_document.h
@@ -49,8 +49,10 @@
   ~CPDF_Document() override;
 
   CPDF_Parser* GetParser() const { return m_pParser.get(); }
-  CPDF_Dictionary* GetRoot() const { return m_pRootDict; }
-  CPDF_Dictionary* GetInfo() const { return m_pInfoDict.Get(); }
+  const CPDF_Dictionary* GetRoot() const { return m_pRootDict; }
+  CPDF_Dictionary* GetRoot() { return m_pRootDict; }
+  const CPDF_Dictionary* GetInfo() const { return m_pInfoDict.Get(); }
+  CPDF_Dictionary* GetInfo() { return m_pInfoDict.Get(); }
 
   void DeletePage(int iPage);
   int GetPageCount() const;
@@ -112,7 +114,7 @@
                     uint32_t* skip_count,
                     uint32_t objnum,
                     int* index,
-                    int level = 0);
+                    int level = 0) const;
   std::unique_ptr<CPDF_Object> ParseIndirectObject(uint32_t objnum) override;
   void LoadDocInternal();
   size_t CalculateEncodingDict(int charset, CPDF_Dictionary* pBaseDict);
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
index 167c1f4..3bd0574 100644
--- a/core/fpdfapi/parser/cpdf_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -1018,7 +1018,7 @@
 
   CPDF_Object* pUnownedObject = pObject.get();
   if (m_pDocument) {
-    CPDF_Dictionary* pRootDict = m_pDocument->GetRoot();
+    const CPDF_Dictionary* pRootDict = m_pDocument->GetRoot();
     if (pRootDict && pRootDict->GetObjNum() == objnum)
       return false;
     if (!m_pDocument->ReplaceIndirectObjectIfHigherGeneration(
diff --git a/core/fpdfdoc/cpdf_action.cpp b/core/fpdfdoc/cpdf_action.cpp
index 557fbda..4d9e630 100644
--- a/core/fpdfdoc/cpdf_action.cpp
+++ b/core/fpdfdoc/cpdf_action.cpp
@@ -85,7 +85,7 @@
   return CFX_WideString();
 }
 
-CFX_ByteString CPDF_Action::GetURI(CPDF_Document* pDoc) const {
+CFX_ByteString CPDF_Action::GetURI(const CPDF_Document* pDoc) const {
   CFX_ByteString csURI;
   if (!m_pDict)
     return csURI;
@@ -93,7 +93,7 @@
     return csURI;
 
   csURI = m_pDict->GetStringFor("URI");
-  CPDF_Dictionary* pRoot = pDoc->GetRoot();
+  const CPDF_Dictionary* pRoot = pDoc->GetRoot();
   CPDF_Dictionary* pURI = pRoot->GetDictFor("URI");
   if (pURI) {
     auto result = csURI.Find(":");
diff --git a/core/fpdfdoc/cpdf_action.h b/core/fpdfdoc/cpdf_action.h
index bd1ce58..be4d461 100644
--- a/core/fpdfdoc/cpdf_action.h
+++ b/core/fpdfdoc/cpdf_action.h
@@ -46,7 +46,7 @@
   ActionType GetType() const;
   CPDF_Dest GetDest(CPDF_Document* pDoc) const;
   CFX_WideString GetFilePath() const;
-  CFX_ByteString GetURI(CPDF_Document* pDoc) const;
+  CFX_ByteString GetURI(const CPDF_Document* pDoc) const;
   bool GetHideStatus() const { return m_pDict->GetBooleanFor("H", true); }
   CFX_ByteString GetNamedAction() const { return m_pDict->GetStringFor("N"); }
   uint32_t GetFlags() const { return m_pDict->GetIntegerFor("Flags"); }
diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp
index 34c8d3a..df3b631 100644
--- a/core/fpdfdoc/cpdf_annotlist.cpp
+++ b/core/fpdfdoc/cpdf_annotlist.cpp
@@ -85,7 +85,7 @@
   if (!pAnnots)
     return;
 
-  CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
+  const CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
   CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm");
   bool bRegenerateAP = pAcroForm && pAcroForm->GetBooleanFor("NeedAppearances");
   for (size_t i = 0; i < pAnnots->GetCount(); ++i) {
diff --git a/core/fpdfdoc/cpdf_bookmarktree.cpp b/core/fpdfdoc/cpdf_bookmarktree.cpp
index b5dfe4f..33c9f3d 100644
--- a/core/fpdfdoc/cpdf_bookmarktree.cpp
+++ b/core/fpdfdoc/cpdf_bookmarktree.cpp
@@ -18,7 +18,7 @@
   if (pParentDict)
     return CPDF_Bookmark(pParentDict->GetDictFor("First"));
 
-  CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
+  const CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
   if (!pRoot)
     return CPDF_Bookmark();
 
diff --git a/core/fpdfdoc/cpdf_metadata.cpp b/core/fpdfdoc/cpdf_metadata.cpp
index 5379275..b31348a 100644
--- a/core/fpdfdoc/cpdf_metadata.cpp
+++ b/core/fpdfdoc/cpdf_metadata.cpp
@@ -11,8 +11,8 @@
 #include "core/fpdfapi/parser/cpdf_stream_acc.h"
 #include "core/fxcrt/xml/cxml_element.h"
 
-CPDF_Metadata::CPDF_Metadata(CPDF_Document* pDoc) {
-  CPDF_Dictionary* pRoot = pDoc->GetRoot();
+CPDF_Metadata::CPDF_Metadata(const CPDF_Document* pDoc) {
+  const CPDF_Dictionary* pRoot = pDoc->GetRoot();
   if (!pRoot)
     return;
 
diff --git a/core/fpdfdoc/cpdf_metadata.h b/core/fpdfdoc/cpdf_metadata.h
index dd68dda..fa95815 100644
--- a/core/fpdfdoc/cpdf_metadata.h
+++ b/core/fpdfdoc/cpdf_metadata.h
@@ -14,7 +14,7 @@
 
 class CPDF_Metadata {
  public:
-  explicit CPDF_Metadata(CPDF_Document* pDoc);
+  explicit CPDF_Metadata(const CPDF_Document* pDoc);
   ~CPDF_Metadata();
 
   const CXML_Element* GetRoot() const;
diff --git a/core/fpdfdoc/cpdf_nametree.cpp b/core/fpdfdoc/cpdf_nametree.cpp
index dc5b6e5..d225d3f 100644
--- a/core/fpdfdoc/cpdf_nametree.cpp
+++ b/core/fpdfdoc/cpdf_nametree.cpp
@@ -299,10 +299,10 @@
 
 CPDF_NameTree::CPDF_NameTree(CPDF_Dictionary* pRoot) : m_pRoot(pRoot) {}
 
-CPDF_NameTree::CPDF_NameTree(CPDF_Document* pDoc,
+CPDF_NameTree::CPDF_NameTree(const CPDF_Document* pDoc,
                              const CFX_ByteString& category)
     : m_pRoot(nullptr) {
-  CPDF_Dictionary* pRoot = pDoc->GetRoot();
+  const CPDF_Dictionary* pRoot = pDoc->GetRoot();
   if (!pRoot)
     return;
 
diff --git a/core/fpdfdoc/cpdf_nametree.h b/core/fpdfdoc/cpdf_nametree.h
index 8c26c93..4dc43fc 100644
--- a/core/fpdfdoc/cpdf_nametree.h
+++ b/core/fpdfdoc/cpdf_nametree.h
@@ -20,7 +20,7 @@
 class CPDF_NameTree {
  public:
   explicit CPDF_NameTree(CPDF_Dictionary* pRoot);
-  CPDF_NameTree(CPDF_Document* pDoc, const CFX_ByteString& category);
+  CPDF_NameTree(const CPDF_Document* pDoc, const CFX_ByteString& category);
   ~CPDF_NameTree();
 
   bool AddValueAndName(std::unique_ptr<CPDF_Object> pObj,
diff --git a/core/fpdfdoc/cpdf_pagelabel.cpp b/core/fpdfdoc/cpdf_pagelabel.cpp
index 41cbb89..7b5e66e 100644
--- a/core/fpdfdoc/cpdf_pagelabel.cpp
+++ b/core/fpdfdoc/cpdf_pagelabel.cpp
@@ -84,7 +84,7 @@
   if (nPage < 0 || nPage >= m_pDocument->GetPageCount())
     return false;
 
-  CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot();
+  const CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot();
   if (!pPDFRoot)
     return false;
 
@@ -124,7 +124,7 @@
   if (!m_pDocument)
     return -1;
 
-  CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot();
+  const CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot();
   if (!pPDFRoot)
     return -1;
 
diff --git a/core/fpdfdoc/cpdf_structtree.cpp b/core/fpdfdoc/cpdf_structtree.cpp
index 62500ac..9168a4f 100644
--- a/core/fpdfdoc/cpdf_structtree.cpp
+++ b/core/fpdfdoc/cpdf_structtree.cpp
@@ -19,8 +19,8 @@
 const int nMaxRecursion = 32;
 
 bool IsTagged(const CPDF_Document* pDoc) {
-  CPDF_Dictionary* pCatalog = pDoc->GetRoot();
-  CPDF_Dictionary* pMarkInfo = pCatalog->GetDictFor("MarkInfo");
+  const CPDF_Dictionary* pCatalog = pDoc->GetRoot();
+  const CPDF_Dictionary* pMarkInfo = pCatalog->GetDictFor("MarkInfo");
   return pMarkInfo && pMarkInfo->GetIntegerFor("Marked");
 }
 
diff --git a/core/fpdfdoc/cpdf_viewerpreferences.cpp b/core/fpdfdoc/cpdf_viewerpreferences.cpp
index f1fc4b0..e25316b 100644
--- a/core/fpdfdoc/cpdf_viewerpreferences.cpp
+++ b/core/fpdfdoc/cpdf_viewerpreferences.cpp
@@ -55,6 +55,6 @@
 }
 
 CPDF_Dictionary* CPDF_ViewerPreferences::GetViewerPreferences() const {
-  CPDF_Dictionary* pDict = m_pDoc->GetRoot();
+  const CPDF_Dictionary* pDict = m_pDoc->GetRoot();
   return pDict ? pDict->GetDictFor("ViewerPreferences") : nullptr;
 }
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index 90d5d94..132e771 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -34,9 +34,11 @@
 bool GenerateWidgetAP(CPDF_Document* pDoc,
                       CPDF_Dictionary* pAnnotDict,
                       const int32_t& nWidgetType) {
-  CPDF_Dictionary* pFormDict = nullptr;
-  if (CPDF_Dictionary* pRootDict = pDoc->GetRoot())
-    pFormDict = pRootDict->GetDictFor("AcroForm");
+  const CPDF_Dictionary* pRootDict = pDoc->GetRoot();
+  if (!pRootDict)
+    return false;
+
+  const CPDF_Dictionary* pFormDict = pRootDict->GetDictFor("AcroForm");
   if (!pFormDict)
     return false;
 
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
index 0a8a59c..a258026 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -593,7 +593,7 @@
   if (!m_pUnderlyingDoc)
     return false;
 
-  CPDF_Dictionary* pRoot = GetPDFDocument()->GetRoot();
+  const CPDF_Dictionary* pRoot = GetPDFDocument()->GetRoot();
   if (!pRoot)
     return false;
 
diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp
index 577faf4..c3ab2b8 100644
--- a/fpdfsdk/formfiller/cba_fontmap.cpp
+++ b/fpdfsdk/formfiller/cba_fontmap.cpp
@@ -89,7 +89,7 @@
     return nullptr;
 
   CPDF_Document* pDocument = GetDocument();
-  CPDF_Dictionary* pRootDict = pDocument->GetRoot();
+  const CPDF_Dictionary* pRootDict = pDocument->GetRoot();
   if (!pRootDict)
     return nullptr;
 
@@ -198,7 +198,8 @@
   CPDF_Dictionary* pAcroFormDict = nullptr;
   const bool bWidget = (m_pAnnotDict->GetStringFor("Subtype") == "Widget");
   if (bWidget) {
-    if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot())
+    const CPDF_Dictionary* pRootDict = m_pDocument->GetRoot();
+    if (pRootDict)
       pAcroFormDict = pRootDict->GetDictFor("AcroForm");
   }
 
diff --git a/fpdfsdk/fpdf_ext.cpp b/fpdfsdk/fpdf_ext.cpp
index 2284453..c8a1b4b 100644
--- a/fpdfsdk/fpdf_ext.cpp
+++ b/fpdfsdk/fpdf_ext.cpp
@@ -126,7 +126,7 @@
     return;
 
   // Portfolios and Packages
-  CPDF_Dictionary* pRootDict = pDoc->GetRoot();
+  const CPDF_Dictionary* pRootDict = pDoc->GetRoot();
   if (pRootDict) {
     CFX_ByteString cbString;
     if (pRootDict->KeyExist("Collection")) {
@@ -174,7 +174,7 @@
   if (!pDoc)
     return PAGEMODE_UNKNOWN;
 
-  CPDF_Dictionary* pRoot = pDoc->GetRoot();
+  const CPDF_Dictionary* pRoot = pDoc->GetRoot();
   if (!pRoot)
     return PAGEMODE_UNKNOWN;
 
diff --git a/fpdfsdk/fpdfdoc.cpp b/fpdfsdk/fpdfdoc.cpp
index 8f81b3a..f73336a 100644
--- a/fpdfsdk/fpdfdoc.cpp
+++ b/fpdfsdk/fpdfdoc.cpp
@@ -387,7 +387,7 @@
   if (!pDoc)
     return 0;
   pDoc->LoadDocumentInfo();
-  CPDF_Dictionary* pInfo = pDoc->GetInfo();
+  const CPDF_Dictionary* pInfo = pDoc->GetInfo();
   if (!pInfo)
     return 0;
   CFX_WideString text = pInfo->GetUnicodeTextFor(tag);
diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp
index 6e142ed..b36c1df 100644
--- a/fpdfsdk/fpdfformfill.cpp
+++ b/fpdfsdk/fpdfformfill.cpp
@@ -721,7 +721,7 @@
     return;
 
   CPDF_Document* pDoc = pFormFillEnv->GetPDFDocument();
-  CPDF_Dictionary* pDict = pDoc->GetRoot();
+  const CPDF_Dictionary* pDict = pDoc->GetRoot();
   if (!pDict)
     return;
 
diff --git a/fpdfsdk/fpdfsave.cpp b/fpdfsdk/fpdfsave.cpp
index 91f8850..455b5ba 100644
--- a/fpdfsdk/fpdfsave.cpp
+++ b/fpdfsdk/fpdfsave.cpp
@@ -62,7 +62,7 @@
   if (!pPDFDocument)
     return false;
 
-  CPDF_Dictionary* pRoot = pPDFDocument->GetRoot();
+  const CPDF_Dictionary* pRoot = pPDFDocument->GetRoot();
   if (!pRoot)
     return false;
 
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index bf8daad..2bc229d 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -564,12 +564,12 @@
   if (!document)
     return false;
 
-  CPDF_Document* pdfDoc =
-      (static_cast<CPDFXFA_Context*>(document))->GetPDFDoc();
-  if (!pdfDoc)
+  const CPDF_Document* pDoc =
+      static_cast<CPDFXFA_Context*>(document)->GetPDFDoc();
+  if (!pDoc)
     return false;
 
-  CPDF_Dictionary* pRoot = pdfDoc->GetRoot();
+  const CPDF_Dictionary* pRoot = pDoc->GetRoot();
   if (!pRoot)
     return false;
 
@@ -587,7 +587,7 @@
 }
 
 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_LoadXFA(FPDF_DOCUMENT document) {
-  return document && (static_cast<CPDFXFA_Context*>(document))->LoadXFADoc();
+  return document && static_cast<CPDFXFA_Context*>(document)->LoadXFADoc();
 }
 #endif  // PDF_ENABLE_XFA
 
@@ -640,7 +640,7 @@
   if (!pDoc)
     return false;
 
-  CPDF_Parser* pParser = pDoc->GetParser();
+  const CPDF_Parser* pParser = pDoc->GetParser();
   if (!pParser)
     return false;
 
@@ -1349,7 +1349,7 @@
   if (!pDoc)
     return 0;
 
-  CPDF_Dictionary* pRoot = pDoc->GetRoot();
+  const CPDF_Dictionary* pRoot = pDoc->GetRoot();
   if (!pRoot)
     return 0;
 
@@ -1445,7 +1445,7 @@
   if (!pDoc)
     return nullptr;
 
-  CPDF_Dictionary* pRoot = pDoc->GetRoot();
+  const CPDF_Dictionary* pRoot = pDoc->GetRoot();
   if (!pRoot)
     return nullptr;
 
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index c0c28db..6537925 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -384,7 +384,7 @@
   if (hDoc != m_pContext->GetXFADoc() || !m_pContext->GetPDFDoc())
     return;
 
-  CPDF_Dictionary* pInfoDict = m_pContext->GetPDFDoc()->GetInfo();
+  const CPDF_Dictionary* pInfoDict = m_pContext->GetPDFDoc()->GetInfo();
   if (!pInfoDict)
     return;
 
@@ -398,7 +398,8 @@
   if (hDoc != m_pContext->GetXFADoc() || !m_pContext->GetPDFDoc())
     return;
 
-  if (CPDF_Dictionary* pInfoDict = m_pContext->GetPDFDoc()->GetInfo())
+  CPDF_Dictionary* pInfoDict = m_pContext->GetPDFDoc()->GetInfo();
+  if (pInfoDict)
     pInfoDict->SetNewFor<CPDF_String>("Title", wsTitle);
 }
 
@@ -449,7 +450,7 @@
     if (!m_pContext->GetPDFDoc())
       return;
 
-    CPDF_Dictionary* pRoot = m_pContext->GetPDFDoc()->GetRoot();
+    const CPDF_Dictionary* pRoot = m_pContext->GetPDFDoc()->GetRoot();
     if (!pRoot)
       return;
 
@@ -750,7 +751,7 @@
     return false;
   }
 
-  CPDF_Dictionary* pRoot = m_pContext->GetPDFDoc()->GetRoot();
+  const CPDF_Dictionary* pRoot = m_pContext->GetPDFDoc()->GetRoot();
   if (!pRoot) {
     fileStream->Flush();
     return false;
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp
index d8934a4..d5875ac 100644
--- a/fpdfsdk/javascript/Document.cpp
+++ b/fpdfsdk/javascript/Document.cpp
@@ -754,7 +754,7 @@
     sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
     return false;
   }
-  CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo();
+  const auto* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo();
   if (!pDictionary)
     return false;
 
diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp
index 4755a17..4d998e1 100644
--- a/xfa/fxfa/cxfa_ffdoc.cpp
+++ b/xfa/fxfa/cxfa_ffdoc.cpp
@@ -286,7 +286,7 @@
   if (!pPDFDoc)
     return false;
 
-  CPDF_Dictionary* pRoot = pPDFDoc->GetRoot();
+  const CPDF_Dictionary* pRoot = pPDFDoc->GetRoot();
   if (!pRoot)
     return false;
 
@@ -347,7 +347,7 @@
     return it->second.pDibSource.As<CFX_DIBitmap>();
   }
 
-  CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot();
+  const CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot();
   if (!pRoot)
     return nullptr;