Return retained references from CPDF_Dictionary::GetObjectFor()
Change-Id: I8ff81284b200ad6c0648ba1d22a3b80ed4685275
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/98153
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp
index 4832276..900d814 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.cpp
+++ b/core/fpdfapi/parser/cpdf_data_avail.cpp
@@ -256,8 +256,13 @@
if (GetValidator()->has_read_problems())
return false;
- const CPDF_Reference* pRef =
- ToReference(m_pRoot ? m_pRoot->GetObjectFor("Pages") : nullptr);
+ if (!m_pRoot) {
+ m_internalStatus = InternalStatus::kError;
+ return false;
+ }
+
+ RetainPtr<const CPDF_Reference> pRef =
+ ToReference(m_pRoot->GetObjectFor("Pages"));
if (!pRef) {
m_internalStatus = InternalStatus::kError;
return false;
@@ -270,8 +275,13 @@
bool CPDF_DataAvail::PreparePageItem() {
const CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
- const CPDF_Reference* pRef =
- ToReference(pRoot ? pRoot->GetObjectFor("Pages") : nullptr);
+ if (!pRoot) {
+ m_internalStatus = InternalStatus::kError;
+ return false;
+ }
+
+ RetainPtr<const CPDF_Reference> pRef =
+ ToReference(pRoot->GetObjectFor("Pages"));
if (!pRef) {
m_internalStatus = InternalStatus::kError;
return false;
@@ -345,7 +355,7 @@
if (!pDict)
return true;
- const CPDF_Object* pKids = pDict->GetObjectFor("Kids");
+ RetainPtr<const CPDF_Object> pKids = pDict->GetObjectFor("Kids");
if (!pKids)
return true;
@@ -979,12 +989,13 @@
if (!pRoot)
return kFormAvailable;
- const CPDF_Object* pAcroForm = pRoot->GetObjectFor("AcroForm");
+ RetainPtr<const CPDF_Object> pAcroForm = pRoot->GetObjectFor("AcroForm");
if (!pAcroForm)
return kFormNotExist;
+ // TODO(tsepez): pass retained argument.
m_pFormAvail = std::make_unique<CPDF_PageObjectAvail>(
- GetValidator(), m_pDocument.Get(), pAcroForm);
+ GetValidator(), m_pDocument.Get(), pAcroForm.Get());
}
switch (m_pFormAvail->CheckAvail()) {
case kDataError:
diff --git a/core/fpdfapi/parser/cpdf_dictionary.cpp b/core/fpdfapi/parser/cpdf_dictionary.cpp
index 2249d07..c63d7fe 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.cpp
+++ b/core/fpdfapi/parser/cpdf_dictionary.cpp
@@ -77,8 +77,9 @@
return it != m_Map.end() ? it->second.Get() : nullptr;
}
-const CPDF_Object* CPDF_Dictionary::GetObjectFor(const ByteString& key) const {
- return GetObjectForInternal(key);
+RetainPtr<const CPDF_Object> CPDF_Dictionary::GetObjectFor(
+ const ByteString& key) const {
+ return pdfium::WrapRetain(GetObjectForInternal(key));
}
RetainPtr<CPDF_Object> CPDF_Dictionary::GetMutableObjectFor(
diff --git a/core/fpdfapi/parser/cpdf_dictionary.h b/core/fpdfapi/parser/cpdf_dictionary.h
index c201b07..be5d843 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.h
+++ b/core/fpdfapi/parser/cpdf_dictionary.h
@@ -43,7 +43,7 @@
bool IsLocked() const { return !!m_LockCount; }
size_t size() const { return m_Map.size(); }
- const CPDF_Object* GetObjectFor(const ByteString& key) const;
+ RetainPtr<const CPDF_Object> GetObjectFor(const ByteString& key) const;
RetainPtr<CPDF_Object> GetMutableObjectFor(const ByteString& key);
RetainPtr<const CPDF_Object> GetDirectObjectFor(const ByteString& key) const;
diff --git a/core/fpdfapi/parser/cpdf_hint_tables.cpp b/core/fpdfapi/parser/cpdf_hint_tables.cpp
index 1695de4..ec73247 100644
--- a/core/fpdfapi/parser/cpdf_hint_tables.cpp
+++ b/core/fpdfapi/parser/cpdf_hint_tables.cpp
@@ -449,7 +449,7 @@
if (!pDict)
return false;
- const CPDF_Object* pOffset = pDict->GetObjectFor("S");
+ RetainPtr<const CPDF_Object> pOffset = pDict->GetObjectFor("S");
if (!pOffset || !pOffset->IsNumber())
return false;
diff --git a/core/fpdfapi/parser/cpdf_object_unittest.cpp b/core/fpdfapi/parser/cpdf_object_unittest.cpp
index 21258e7..e81c573 100644
--- a/core/fpdfapi/parser/cpdf_object_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_object_unittest.cpp
@@ -149,7 +149,7 @@
return false;
CPDF_DictionaryLocker locker1(dict1);
for (const auto& item : locker1) {
- if (!Equal(item.second.Get(), dict2->GetObjectFor(item.first)))
+ if (!Equal(item.second.Get(), dict2->GetObjectFor(item.first).Get()))
return false;
}
return true;
@@ -924,7 +924,7 @@
auto dict = pdfium::MakeRetain<CPDF_Dictionary>();
dict->SetNewFor<CPDF_Reference>("foo", &objects_holder, 1234);
ASSERT_EQ(1U, dict->size());
- const CPDF_Object* obj = dict->GetObjectFor("foo");
+ RetainPtr<const CPDF_Object> obj = dict->GetObjectFor("foo");
ASSERT_TRUE(obj);
EXPECT_TRUE(obj->IsReference());
@@ -935,7 +935,7 @@
RetainPtr<CPDF_Dictionary> cloned_dict =
ToDictionary(std::move(cloned_dict_object));
ASSERT_EQ(0U, cloned_dict->size());
- const CPDF_Object* cloned_obj = cloned_dict->GetObjectFor("foo");
+ RetainPtr<const CPDF_Object> cloned_obj = cloned_dict->GetObjectFor("foo");
EXPECT_FALSE(cloned_obj);
}
@@ -993,7 +993,7 @@
ToDictionary(dict_obj->CloneDirectObject());
// Cloned object should be the same as the original.
ASSERT_TRUE(cloned_dict);
- const CPDF_Object* cloned_arr = cloned_dict->GetObjectFor("arr");
+ RetainPtr<const CPDF_Object> cloned_arr = cloned_dict->GetObjectFor("arr");
ASSERT_TRUE(cloned_arr);
ASSERT_TRUE(cloned_arr->IsArray());
EXPECT_EQ(0U, cloned_arr->AsArray()->size());
@@ -1008,7 +1008,7 @@
auto dict = pdfium::MakeRetain<CPDF_Dictionary>();
CPDF_Object* pObj = dict->SetNewFor<CPDF_Number>("clams", 42);
dict->ConvertToIndirectObjectFor("clams", &objects_holder);
- const CPDF_Object* pRef = dict->GetObjectFor("clams");
+ RetainPtr<const CPDF_Object> pRef = dict->GetObjectFor("clams");
RetainPtr<const CPDF_Object> pNum = dict->GetDirectObjectFor("clams");
EXPECT_TRUE(pRef->IsReference());
EXPECT_TRUE(pNum->IsNumber());
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
index bd0deb6..3eac803 100644
--- a/core/fpdfapi/parser/cpdf_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -271,7 +271,7 @@
return eRet;
}
if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) {
- const CPDF_Reference* pMetadata =
+ RetainPtr<const CPDF_Reference> pMetadata =
ToReference(GetRoot()->GetObjectFor("Metadata"));
if (pMetadata)
m_MetadataObjnum = pMetadata->GetRefObjNum();
@@ -865,12 +865,13 @@
if (!GetTrailer())
return nullptr;
- const CPDF_Object* pEncryptObj = GetTrailer()->GetObjectFor("Encrypt");
+ RetainPtr<const CPDF_Object> pEncryptObj =
+ GetTrailer()->GetObjectFor("Encrypt");
if (!pEncryptObj)
return nullptr;
if (pEncryptObj->IsDictionary())
- return ToDictionary(pEncryptObj);
+ return pEncryptObj->AsDictionary();
if (pEncryptObj->IsReference()) {
// TODO(tsepez): return retained object.
@@ -900,7 +901,7 @@
}
uint32_t CPDF_Parser::GetInfoObjNum() const {
- const CPDF_Reference* pRef =
+ RetainPtr<const CPDF_Reference> pRef =
ToReference(m_CrossRefTable->trailer()
? m_CrossRefTable->trailer()->GetObjectFor("Info")
: nullptr);
@@ -908,7 +909,7 @@
}
uint32_t CPDF_Parser::GetRootObjNum() const {
- const CPDF_Reference* pRef =
+ RetainPtr<const CPDF_Reference> pRef =
ToReference(m_CrossRefTable->trailer()
? m_CrossRefTable->trailer()->GetObjectFor("Root")
: nullptr);
@@ -1091,7 +1092,7 @@
}
if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) {
- const CPDF_Reference* pMetadata =
+ RetainPtr<const CPDF_Reference> pMetadata =
ToReference(GetRoot()->GetObjectFor("Metadata"));
if (pMetadata)
m_MetadataObjnum = pMetadata->GetRefObjNum();
diff --git a/core/fpdfdoc/cpdf_interactiveform.cpp b/core/fpdfdoc/cpdf_interactiveform.cpp
index 1022e35..cac1dde 100644
--- a/core/fpdfdoc/cpdf_interactiveform.cpp
+++ b/core/fpdfdoc/cpdf_interactiveform.cpp
@@ -839,7 +839,7 @@
auto newField = std::make_unique<CPDF_FormField>(this, pParent.Get());
pField = newField.get();
- const CPDF_Object* pTObj =
+ RetainPtr<const CPDF_Object> pTObj =
pFieldDict->GetObjectFor(pdfium::form_fields::kT);
if (ToReference(pTObj)) {
RetainPtr<CPDF_Object> pClone = pTObj->CloneDirectObject();
diff --git a/core/fpdfdoc/cpdf_structelement.cpp b/core/fpdfdoc/cpdf_structelement.cpp
index 679e21c..ee6f548 100644
--- a/core/fpdfdoc/cpdf_structelement.cpp
+++ b/core/fpdfdoc/cpdf_structelement.cpp
@@ -93,11 +93,9 @@
}
void CPDF_StructElement::LoadKids(const CPDF_Dictionary* pDict) {
- const CPDF_Object* pObj = pDict->GetObjectFor("Pg");
- uint32_t PageObjNum = 0;
- if (const CPDF_Reference* pRef = ToReference(pObj))
- PageObjNum = pRef->GetRefObjNum();
-
+ RetainPtr<const CPDF_Object> pObj = pDict->GetObjectFor("Pg");
+ const CPDF_Reference* pRef = ToReference(pObj.Get());
+ const uint32_t PageObjNum = pRef ? pRef->GetRefObjNum() : 0;
RetainPtr<const CPDF_Object> pKids = pDict->GetDirectObjectFor("K");
if (!pKids)
return;
@@ -140,9 +138,10 @@
if (!pKidDict)
return;
- if (const CPDF_Reference* pRef = ToReference(pKidDict->GetObjectFor("Pg")))
+ if (RetainPtr<const CPDF_Reference> pRef =
+ ToReference(pKidDict->GetObjectFor("Pg"))) {
PageObjNum = pRef->GetRefObjNum();
-
+ }
ByteString type = pKidDict->GetNameFor("Type");
if ((type == "MCR" || type == "OBJR") &&
m_pTree->GetPage()->GetObjNum() != PageObjNum) {
@@ -151,7 +150,8 @@
if (type == "MCR") {
pKid->m_Type = Kid::kStreamContent;
- const CPDF_Reference* pRef = ToReference(pKidDict->GetObjectFor("Stm"));
+ RetainPtr<const CPDF_Reference> pRef =
+ ToReference(pKidDict->GetObjectFor("Stm"));
pKid->m_RefObjNum = pRef ? pRef->GetRefObjNum() : 0;
pKid->m_PageObjNum = PageObjNum;
pKid->m_ContentId = pKidDict->GetIntegerFor("MCID");
@@ -160,7 +160,8 @@
if (type == "OBJR") {
pKid->m_Type = Kid::kObject;
- const CPDF_Reference* pObj = ToReference(pKidDict->GetObjectFor("Obj"));
+ RetainPtr<const CPDF_Reference> pObj =
+ ToReference(pKidDict->GetObjectFor("Obj"));
pKid->m_RefObjNum = pObj ? pObj->GetRefObjNum() : 0;
pKid->m_PageObjNum = PageObjNum;
return;
diff --git a/core/fpdfdoc/cpdf_viewerpreferences.cpp b/core/fpdfdoc/cpdf_viewerpreferences.cpp
index 8ce48cd..c6ebe97 100644
--- a/core/fpdfdoc/cpdf_viewerpreferences.cpp
+++ b/core/fpdfdoc/cpdf_viewerpreferences.cpp
@@ -47,7 +47,7 @@
if (!pDict)
return absl::nullopt;
- const CPDF_Name* pName = ToName(pDict->GetObjectFor(bsKey));
+ RetainPtr<const CPDF_Name> pName = ToName(pDict->GetObjectFor(bsKey));
if (!pName)
return absl::nullopt;
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index eb75f96..a2524b6 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -831,7 +831,8 @@
pDict = item->GetParam();
if (!pDict)
continue;
- const CPDF_String* temp = ToString(pDict->GetObjectFor("ActualText"));
+ RetainPtr<const CPDF_String> temp =
+ ToString(pDict->GetObjectFor("ActualText"));
if (temp) {
bExist = true;
actText = temp->GetUnicodeText();
diff --git a/fpdfsdk/fpdf_annot.cpp b/fpdfsdk/fpdf_annot.cpp
index 75bdf6c..253e25f 100644
--- a/fpdfsdk/fpdf_annot.cpp
+++ b/fpdfsdk/fpdf_annot.cpp
@@ -1007,7 +1007,7 @@
return FPDF_OBJECT_UNKNOWN;
const CPDF_AnnotContext* pAnnot = CPDFAnnotContextFromFPDFAnnotation(annot);
- const CPDF_Object* pObj = pAnnot->GetAnnotDict()->GetObjectFor(key);
+ RetainPtr<const CPDF_Object> pObj = pAnnot->GetAnnotDict()->GetObjectFor(key);
return pObj ? pObj->GetType() : FPDF_OBJECT_UNKNOWN;
}
@@ -1049,7 +1049,7 @@
if (!pAnnotDict)
return false;
- const CPDF_Object* p = pAnnotDict->GetObjectFor(key);
+ RetainPtr<const CPDF_Object> p = pAnnotDict->GetObjectFor(key);
if (!p || p->GetType() != FPDF_OBJECT_NUMBER)
return false;
diff --git a/fpdfsdk/fpdf_attachment.cpp b/fpdfsdk/fpdf_attachment.cpp
index a7978dc..d84acd8 100644
--- a/fpdfsdk/fpdf_attachment.cpp
+++ b/fpdfsdk/fpdf_attachment.cpp
@@ -145,7 +145,7 @@
return FPDF_OBJECT_UNKNOWN;
CPDF_FileSpec spec(CPDFObjectFromFPDFAttachment(attachment));
- const CPDF_Object* pObj = spec.GetParamsDict()->GetObjectFor(key);
+ RetainPtr<const CPDF_Object> pObj = spec.GetParamsDict()->GetObjectFor(key);
return pObj ? pObj->GetType() : FPDF_OBJECT_UNKNOWN;
}
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp
index 742b479..d4fe040 100644
--- a/fpdfsdk/fpdf_edit_embeddertest.cpp
+++ b/fpdfsdk/fpdf_edit_embeddertest.cpp
@@ -3020,11 +3020,13 @@
const CPDF_Dictionary* cidinfo_dict =
cidfont_dict->GetDictFor("CIDSystemInfo");
ASSERT_TRUE(cidinfo_dict);
- const CPDF_Object* registry = cidinfo_dict->GetObjectFor("Registry");
+ RetainPtr<const CPDF_Object> registry =
+ cidinfo_dict->GetObjectFor("Registry");
ASSERT_TRUE(registry);
EXPECT_EQ(CPDF_Object::kString, registry->GetType());
EXPECT_EQ("Adobe", registry->GetString());
- const CPDF_Object* ordering = cidinfo_dict->GetObjectFor("Ordering");
+ RetainPtr<const CPDF_Object> ordering =
+ cidinfo_dict->GetObjectFor("Ordering");
ASSERT_TRUE(ordering);
EXPECT_EQ(CPDF_Object::kString, ordering->GetType());
EXPECT_EQ("Identity", ordering->GetString());
diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp
index 568b9b4..3fde9c7 100644
--- a/fpdfsdk/fpdf_editpage.cpp
+++ b/fpdfsdk/fpdf_editpage.cpp
@@ -403,7 +403,7 @@
if (!pParams)
return FPDF_OBJECT_UNKNOWN;
- const CPDF_Object* pObject = pParams->GetObjectFor(key);
+ RetainPtr<const CPDF_Object> pObject = pParams->GetObjectFor(key);
return pObject ? pObject->GetType() : FPDF_OBJECT_UNKNOWN;
}
@@ -418,7 +418,7 @@
if (!pParams)
return false;
- const CPDF_Object* pObj = pParams->GetObjectFor(key);
+ RetainPtr<const CPDF_Object> pObj = pParams->GetObjectFor(key);
if (!pObj || !pObj->IsNumber())
return false;
@@ -439,7 +439,7 @@
if (!pParams)
return false;
- const CPDF_Object* pObj = pParams->GetObjectFor(key);
+ RetainPtr<const CPDF_Object> pObj = pParams->GetObjectFor(key);
if (!pObj || !pObj->IsString())
return false;
@@ -461,7 +461,7 @@
if (!pParams)
return false;
- const CPDF_Object* pObj = pParams->GetObjectFor(key);
+ RetainPtr<const CPDF_Object> pObj = pParams->GetObjectFor(key);
if (!pObj || !pObj->IsString())
return false;
diff --git a/fpdfsdk/fpdf_ext.cpp b/fpdfsdk/fpdf_ext.cpp
index 37e123c..92ca09a 100644
--- a/fpdfsdk/fpdf_ext.cpp
+++ b/fpdfsdk/fpdf_ext.cpp
@@ -90,7 +90,7 @@
if (!pRoot)
return PAGEMODE_UNKNOWN;
- const CPDF_Object* pName = pRoot->GetObjectFor("PageMode");
+ RetainPtr<const CPDF_Object> pName = pRoot->GetObjectFor("PageMode");
if (!pName)
return PAGEMODE_USENONE;
diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp
index d6cdc4e..68489a4 100644
--- a/fpdfsdk/fpdf_ppo.cpp
+++ b/fpdfsdk/fpdf_ppo.cpp
@@ -168,12 +168,13 @@
if (!pp)
return nullptr;
+ // TODO(tsepez): return retained objects throughout.
if (pDict->KeyExist(bsSrcTag))
- return pDict->GetObjectFor(bsSrcTag);
+ return pDict->GetObjectFor(bsSrcTag).Get();
while (pp) {
if (pp->KeyExist(bsSrcTag))
- return pp->GetObjectFor(bsSrcTag);
+ return pp->GetObjectFor(bsSrcTag).Get();
if (!pp->KeyExist(pdfium::page_object::kParent))
break;
pp = ToDictionary(
diff --git a/fpdfsdk/fpdf_signature.cpp b/fpdfsdk/fpdf_signature.cpp
index 1daa2a5..8fce2f4 100644
--- a/fpdfsdk/fpdf_signature.cpp
+++ b/fpdfsdk/fpdf_signature.cpp
@@ -140,7 +140,7 @@
if (!value_dict)
return 0;
- const CPDF_Object* obj = value_dict->GetObjectFor("Reason");
+ RetainPtr<const CPDF_Object> obj = value_dict->GetObjectFor("Reason");
if (!obj || !obj->IsString())
return 0;
@@ -161,7 +161,7 @@
if (!value_dict)
return 0;
- const CPDF_Object* obj = value_dict->GetObjectFor("M");
+ RetainPtr<const CPDF_Object> obj = value_dict->GetObjectFor("M");
if (!obj || !obj->IsString())
return 0;
diff --git a/fpdfsdk/fpdf_structtree.cpp b/fpdfsdk/fpdf_structtree.cpp
index 4fa11c9..e18bd84 100644
--- a/fpdfsdk/fpdf_structtree.cpp
+++ b/fpdfsdk/fpdf_structtree.cpp
@@ -34,7 +34,7 @@
int GetMcidFromDict(const CPDF_Dictionary* dict) {
if (dict && dict->GetNameFor("Type") == "MCR") {
- const CPDF_Object* obj = dict->GetObjectFor("MCID");
+ RetainPtr<const CPDF_Object> obj = dict->GetObjectFor("MCID");
if (obj && obj->IsNumber())
return obj->GetInteger();
}
@@ -109,7 +109,7 @@
const CPDF_Dictionary* dict = elem ? elem->GetDict() : nullptr;
if (!dict)
return 0;
- const CPDF_Object* obj = dict->GetObjectFor("ID");
+ RetainPtr<const CPDF_Object> obj = dict->GetObjectFor("ID");
if (!obj || !obj->IsString())
return 0;
return Utf16EncodeMaybeCopyAndReturnLength(obj->GetUnicodeText(), buffer,
@@ -125,7 +125,7 @@
const CPDF_Dictionary* dict = elem ? elem->GetDict() : nullptr;
if (!dict)
return 0;
- const CPDF_Object* obj = dict->GetObjectFor("Lang");
+ RetainPtr<const CPDF_Object> obj = dict->GetObjectFor("Lang");
if (!obj || !obj->IsString())
return 0;
return Utf16EncodeMaybeCopyAndReturnLength(obj->GetUnicodeText(), buffer,
@@ -137,7 +137,8 @@
CPDF_StructElement* elem =
CPDFStructElementFromFPDFStructElement(struct_element);
const CPDF_Dictionary* dict = elem ? elem->GetDict() : nullptr;
- const CPDF_Object* attr_obj = dict ? dict->GetObjectFor("A") : nullptr;
+ RetainPtr<const CPDF_Object> attr_obj =
+ dict ? dict->GetObjectFor("A") : nullptr;
if (!attr_obj)
return -1;
@@ -152,7 +153,8 @@
CPDF_StructElement* elem =
CPDFStructElementFromFPDFStructElement(struct_element);
const CPDF_Dictionary* dict = elem ? elem->GetDict() : nullptr;
- const CPDF_Object* attr_obj = dict ? dict->GetObjectFor("A") : nullptr;
+ RetainPtr<const CPDF_Object> attr_obj =
+ dict ? dict->GetObjectFor("A") : nullptr;
if (!attr_obj)
return nullptr;
@@ -190,7 +192,7 @@
const CPDF_Dictionary* obj_dict = obj->AsDictionary();
if (!obj_dict)
continue;
- const CPDF_Object* attr = obj_dict->GetObjectFor(attr_name);
+ RetainPtr<const CPDF_Object> attr = obj_dict->GetObjectFor(attr_name);
if (!attr || !(attr->IsString() || attr->IsName()))
continue;
return Utf16EncodeMaybeCopyAndReturnLength(attr->GetUnicodeText(), buffer,
@@ -203,7 +205,8 @@
FPDF_StructElement_GetMarkedContentID(FPDF_STRUCTELEMENT struct_element) {
CPDF_StructElement* elem =
CPDFStructElementFromFPDFStructElement(struct_element);
- const CPDF_Object* p = elem ? elem->GetDict()->GetObjectFor("K") : nullptr;
+ RetainPtr<const CPDF_Object> p =
+ elem ? elem->GetDict()->GetObjectFor("K") : nullptr;
return p && p->IsNumber() ? p->GetInteger() : -1;
}
@@ -316,7 +319,7 @@
if (!dict)
return FPDF_OBJECT_UNKNOWN;
- const CPDF_Object* obj = dict->GetObjectFor(name);
+ RetainPtr<const CPDF_Object> obj = dict->GetObjectFor(name);
return obj ? obj->GetType() : FPDF_OBJECT_UNKNOWN;
}
@@ -332,7 +335,7 @@
if (!dict)
return false;
- const CPDF_Object* obj = dict->GetObjectFor(name);
+ RetainPtr<const CPDF_Object> obj = dict->GetObjectFor(name);
if (!obj || !obj->IsBoolean())
return false;
@@ -352,7 +355,7 @@
if (!dict)
return false;
- const CPDF_Object* obj = dict->GetObjectFor(name);
+ RetainPtr<const CPDF_Object> obj = dict->GetObjectFor(name);
if (!obj || !obj->IsNumber())
return false;
@@ -374,7 +377,7 @@
if (!dict)
return false;
- const CPDF_Object* obj = dict->GetObjectFor(name);
+ RetainPtr<const CPDF_Object> obj = dict->GetObjectFor(name);
if (!obj || !(obj->IsString() || obj->IsName()))
return false;
@@ -397,7 +400,7 @@
if (!dict)
return false;
- const CPDF_Object* obj = dict->GetObjectFor(name);
+ RetainPtr<const CPDF_Object> obj = dict->GetObjectFor(name);
if (!obj || !obj->IsString())
return false;
@@ -416,7 +419,7 @@
CPDF_StructElement* elem =
CPDFStructElementFromFPDFStructElement(struct_element);
const CPDF_Dictionary* dict = elem ? elem->GetDict() : nullptr;
- const CPDF_Object* p = dict ? dict->GetObjectFor("K") : nullptr;
+ RetainPtr<const CPDF_Object> p = dict ? dict->GetObjectFor("K") : nullptr;
if (!p)
return -1;
@@ -432,7 +435,7 @@
CPDF_StructElement* elem =
CPDFStructElementFromFPDFStructElement(struct_element);
const CPDF_Dictionary* dict = elem ? elem->GetDict() : nullptr;
- const CPDF_Object* p = dict ? dict->GetObjectFor("K") : nullptr;
+ RetainPtr<const CPDF_Object> p = dict ? dict->GetObjectFor("K") : nullptr;
if (!p)
return -1;
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index de2bfef..1ca876f 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -105,8 +105,9 @@
if (!root)
return nullptr;
+ // TODO(tsepez): return retained objects.
const CPDF_Dictionary* acro_form = root->GetDictFor("AcroForm");
- return acro_form ? acro_form->GetObjectFor("XFA") : nullptr;
+ return acro_form ? acro_form->GetObjectFor("XFA").Get() : nullptr;
}
struct XFAPacket {
@@ -252,7 +253,7 @@
if (!pAcroForm)
return FORMTYPE_NONE;
- const CPDF_Object* pXFA = pAcroForm->GetObjectFor("XFA");
+ RetainPtr<const CPDF_Object> pXFA = pAcroForm->GetObjectFor("XFA");
if (!pXFA)
return FORMTYPE_ACRO_FORM;
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index 0d048d3..bcdeb43 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -464,7 +464,8 @@
if (!pAcroForm)
return;
- const CPDF_Array* pArray = ToArray(pAcroForm->GetObjectFor("XFA"));
+ RetainPtr<const CPDF_Array> pArray =
+ ToArray(pAcroForm->GetObjectFor("XFA"));
if (!pArray)
return;