summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-10-26 13:02:07 -0400
committerDan Sinclair <dsinclair@chromium.org>2015-10-26 13:02:07 -0400
commit7e155865c90cc1115cc7193b7646a341d8f9093e (patch)
tree44e4351192f0af909671df95a1aac16a1609f750 /core
parent9024e026dae1af064b8467bb0f62278417fb82d1 (diff)
downloadpdfium-7e155865c90cc1115cc7193b7646a341d8f9093e.tar.xz
Revert "Add type cast definitions for CPDF_Reference."
This is causing pixel test failures on the bots. FAILURE: bug_543018_2.in FAILURE: bug_543018_1.in FAILURE: bug_524043_1.in This reverts commit 9024e026dae1af064b8467bb0f62278417fb82d1. Add type cast definitions for CPDF_Reference. This Cl adds ToReference, CPDF_Object::AsReference and CPDF_Object::IsReference and updates the src to use them as needed. BUG=pdfium:201 TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1420973002 . Review URL: https://codereview.chromium.org/1414393006 .
Diffstat (limited to 'core')
-rw-r--r--core/include/fpdfapi/fpdf_objects.h11
-rw-r--r--core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp20
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp53
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp13
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp107
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp135
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp3
-rw-r--r--core/src/fpdfdoc/doc_form.cpp7
-rw-r--r--core/src/fpdfdoc/doc_tagged.cpp30
9 files changed, 224 insertions, 155 deletions
diff --git a/core/include/fpdfapi/fpdf_objects.h b/core/include/fpdfapi/fpdf_objects.h
index 419d5fc23e..45ca665b99 100644
--- a/core/include/fpdfapi/fpdf_objects.h
+++ b/core/include/fpdfapi/fpdf_objects.h
@@ -84,7 +84,6 @@ class CPDF_Object {
bool IsDictionary() const { return m_Type == PDFOBJ_DICTIONARY; }
bool IsName() const { return m_Type == PDFOBJ_NAME; }
bool IsNumber() const { return m_Type == PDFOBJ_NUMBER; }
- bool IsReference() const { return m_Type == PDFOBJ_REFERENCE; }
bool IsStream() const { return m_Type == PDFOBJ_STREAM; }
bool IsString() const { return m_Type == PDFOBJ_STRING; }
@@ -103,9 +102,6 @@ class CPDF_Object {
CPDF_Number* AsNumber();
const CPDF_Number* AsNumber() const;
- CPDF_Reference* AsReference();
- const CPDF_Reference* AsReference() const;
-
CPDF_Stream* AsStream();
const CPDF_Stream* AsStream() const;
@@ -604,13 +600,6 @@ class CPDF_Reference : public CPDF_Object {
FX_DWORD m_RefObjNum;
friend class CPDF_Object;
};
-inline CPDF_Reference* ToReference(CPDF_Object* obj) {
- return obj ? obj->AsReference() : nullptr;
-}
-inline const CPDF_Reference* ToReference(const CPDF_Object* obj) {
- return obj ? obj->AsReference() : nullptr;
-}
-
class CPDF_IndirectObjects {
public:
CPDF_IndirectObjects(CPDF_Parser* pParser);
diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
index fec4e4f8e1..16124a3c38 100644
--- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
+++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
@@ -61,12 +61,16 @@ int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj,
break;
}
case PDFOBJ_REFERENCE: {
- if (pFile->AppendString(FX_BSTRC(" ")) < 0)
+ if (pFile->AppendString(FX_BSTRC(" ")) < 0) {
return -1;
- if ((len = pFile->AppendDWord(pObj->AsReference()->GetRefObjNum())) < 0)
+ }
+ CPDF_Reference* p = (CPDF_Reference*)pObj;
+ if ((len = pFile->AppendDWord(p->GetRefObjNum())) < 0) {
return -1;
- if (pFile->AppendString(FX_BSTRC(" 0 R ")) < 0)
+ }
+ if (pFile->AppendString(FX_BSTRC(" 0 R ")) < 0) {
return -1;
+ }
offset += len + 6;
break;
}
@@ -1164,12 +1168,16 @@ int32_t CPDF_Creator::WriteDirectObj(FX_DWORD objnum,
break;
}
case PDFOBJ_REFERENCE: {
- if (m_File.AppendString(FX_BSTRC(" ")) < 0)
+ if (m_File.AppendString(FX_BSTRC(" ")) < 0) {
return -1;
- if ((len = m_File.AppendDWord(pObj->AsReference()->GetRefObjNum())) < 0)
+ }
+ CPDF_Reference* p = (CPDF_Reference*)pObj;
+ if ((len = m_File.AppendDWord(p->GetRefObjNum())) < 0) {
return -1;
- if (m_File.AppendString(FX_BSTRC(" 0 R")) < 0)
+ }
+ if (m_File.AppendString(FX_BSTRC(" 0 R")) < 0) {
return -1;
+ }
m_Offset += len + 5;
break;
}
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index b12a65a844..3295b7f9e0 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -671,28 +671,51 @@ void CPDF_StreamContentParser::Handle_ExecuteXObject() {
CFX_ByteString name = GetString(0);
if (name == m_LastImageName && m_pLastImage && m_pLastImage->GetStream() &&
m_pLastImage->GetStream()->GetObjNum()) {
- AddImage(nullptr, m_pLastImage, FALSE);
+ AddImage(NULL, m_pLastImage, FALSE);
return;
}
-
if (m_Options.m_bTextOnly) {
- if (!m_pResources)
- return;
-
- CPDF_Dictionary* pList = m_pResources->GetDict(FX_BSTRC("XObject"));
- if (!pList && m_pPageResources && m_pResources != m_pPageResources)
- pList = m_pPageResources->GetDict(FX_BSTRC("XObject"));
- if (!pList)
+ CPDF_Object* pRes = NULL;
+ if (m_pResources == NULL) {
return;
- CPDF_Reference* pRes = ToReference(pList->GetElement(name));
- if (!pRes)
- return;
-
+ }
+ if (m_pResources == m_pPageResources) {
+ CPDF_Dictionary* pList = m_pResources->GetDict(FX_BSTRC("XObject"));
+ if (pList == NULL) {
+ return;
+ }
+ pRes = pList->GetElement(name);
+ if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) {
+ return;
+ }
+ } else {
+ CPDF_Dictionary* pList = m_pResources->GetDict(FX_BSTRC("XObject"));
+ if (pList == NULL) {
+ if (m_pPageResources == NULL) {
+ return;
+ }
+ CPDF_Dictionary* pList = m_pPageResources->GetDict(FX_BSTRC("XObject"));
+ if (pList == NULL) {
+ return;
+ }
+ pRes = pList->GetElement(name);
+ if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) {
+ return;
+ }
+ } else {
+ pRes = pList->GetElement(name);
+ if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) {
+ return;
+ }
+ }
+ }
FX_BOOL bForm;
- if (m_pDocument->IsFormStream(pRes->GetRefObjNum(), bForm) && !bForm)
+ if (m_pDocument->IsFormStream(((CPDF_Reference*)pRes)->GetRefObjNum(),
+ bForm) &&
+ !bForm) {
return;
+ }
}
-
CPDF_Stream* pXObject = ToStream(FindResourceObj(FX_BSTRC("XObject"), name));
if (!pXObject) {
m_bResourceMissing = TRUE;
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp
index 67c18f8ae0..5333fe8087 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp
@@ -190,8 +190,9 @@ int CPDF_Document::_FindPageIndex(CPDF_Dictionary* pNode,
}
if (count && count == pKidList->GetCount()) {
for (FX_DWORD i = 0; i < count; i++) {
- if (CPDF_Reference* pKid = ToReference(pKidList->GetElement(i))) {
- if (pKid->GetRefObjNum() == objnum) {
+ CPDF_Object* pKid = pKidList->GetElement(i);
+ if (pKid && pKid->GetType() == PDFOBJ_REFERENCE) {
+ if (((CPDF_Reference*)pKid)->GetRefObjNum() == objnum) {
m_PageList.SetAt(index + i, objnum);
return index + i;
}
@@ -307,9 +308,13 @@ FX_BOOL CPDF_Document::IsContentUsedElsewhere(FX_DWORD objnum,
if (pContents->GetDirectType() == PDFOBJ_ARRAY) {
CPDF_Array* pArray = pContents->GetDirect()->AsArray();
for (FX_DWORD j = 0; j < pArray->GetCount(); j++) {
- CPDF_Reference* pRef = ToReference(pArray->GetElement(j));
- if (pRef && pRef->GetRefObjNum() == objnum)
+ CPDF_Object* pRef = pArray->GetElement(j);
+ if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) {
+ continue;
+ }
+ if (((CPDF_Reference*)pRef)->GetRefObjNum() == objnum) {
return TRUE;
+ }
}
} else if (pContents->GetObjNum() == objnum) {
return TRUE;
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
index 07b1a208d7..fc473319fc 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
@@ -48,13 +48,16 @@ CFX_ByteString CPDF_Object::GetString() const {
case PDFOBJ_NAME:
return AsName()->m_Name;
case PDFOBJ_REFERENCE: {
- const CPDF_Reference* pRef = AsReference();
- if (!pRef->m_pObjList)
+ CPDF_Reference* pRef = (CPDF_Reference*)(void*)this;
+ if (pRef->m_pObjList == NULL) {
break;
-
+ }
CPDF_Object* pObj =
pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum());
- return pObj ? pObj->GetString() : CFX_ByteString();
+ if (pObj == NULL) {
+ return CFX_ByteString();
+ }
+ return pObj->GetString();
}
}
return CFX_ByteString();
@@ -70,13 +73,16 @@ CFX_ByteStringC CPDF_Object::GetConstString() const {
return CFX_ByteStringC((const uint8_t*)name, name.GetLength());
}
case PDFOBJ_REFERENCE: {
- const CPDF_Reference* pRef = AsReference();
- if (!pRef->m_pObjList)
+ CPDF_Reference* pRef = (CPDF_Reference*)(void*)this;
+ if (pRef->m_pObjList == NULL) {
break;
-
+ }
CPDF_Object* pObj =
pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum());
- return pObj ? pObj->GetConstString() : CFX_ByteStringC();
+ if (pObj == NULL) {
+ return CFX_ByteStringC();
+ }
+ return pObj->GetConstString();
}
}
return CFX_ByteStringC();
@@ -86,13 +92,16 @@ FX_FLOAT CPDF_Object::GetNumber() const {
case PDFOBJ_NUMBER:
return AsNumber()->GetNumber();
case PDFOBJ_REFERENCE: {
- const CPDF_Reference* pRef = AsReference();
- if (!pRef->m_pObjList)
+ CPDF_Reference* pRef = (CPDF_Reference*)(void*)this;
+ if (pRef->m_pObjList == NULL) {
break;
-
+ }
CPDF_Object* pObj =
pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum());
- return pObj ? pObj->GetNumber() : 0;
+ if (pObj == NULL) {
+ return 0;
+ }
+ return pObj->GetNumber();
}
}
return 0;
@@ -111,15 +120,18 @@ int CPDF_Object::GetInteger() const {
case PDFOBJ_NUMBER:
return AsNumber()->GetInteger();
case PDFOBJ_REFERENCE: {
- const CPDF_Reference* pRef = AsReference();
+ CPDF_Reference* pRef = (CPDF_Reference*)(void*)this;
PARSE_CONTEXT context;
FXSYS_memset(&context, 0, sizeof(PARSE_CONTEXT));
- if (!pRef->m_pObjList)
+ if (pRef->m_pObjList == NULL) {
return 0;
-
+ }
CPDF_Object* pObj =
pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum(), &context);
- return pObj ? pObj->GetInteger() : 0;
+ if (pObj == NULL) {
+ return 0;
+ }
+ return pObj->GetInteger();
}
}
return 0;
@@ -134,7 +146,7 @@ CPDF_Dictionary* CPDF_Object::GetDict() const {
case PDFOBJ_STREAM:
return AsStream()->GetDict();
case PDFOBJ_REFERENCE: {
- const CPDF_Reference* pRef = AsReference();
+ CPDF_Reference* pRef = (CPDF_Reference*)this;
CPDF_IndirectObjects* pIndirect = pRef->GetObjList();
if (!pIndirect)
return nullptr;
@@ -172,21 +184,26 @@ void CPDF_Object::SetString(const CFX_ByteString& str) {
ASSERT(FALSE);
}
int CPDF_Object::GetDirectType() const {
- const CPDF_Reference* pRef = AsReference();
- if (!pRef)
+ if (m_Type != PDFOBJ_REFERENCE) {
return m_Type;
+ }
+ CPDF_Reference* pRef = (CPDF_Reference*)this;
return pRef->m_pObjList->GetIndirectType(pRef->GetRefObjNum());
}
FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const {
- if (this == pOther)
+ if (this == pOther) {
return TRUE;
- if (!pOther)
+ }
+ if (pOther == NULL) {
return FALSE;
+ }
if (pOther->m_Type != m_Type) {
- if (IsReference() && GetDirect())
+ if (m_Type == PDFOBJ_REFERENCE && GetDirect()) {
return GetDirect()->IsIdentical(pOther);
- if (pOther->IsReference())
+ }
+ if (pOther->m_Type == PDFOBJ_REFERENCE) {
return IsIdentical(pOther->GetDirect());
+ }
return FALSE;
}
switch (m_Type) {
@@ -207,16 +224,18 @@ FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const {
case PDFOBJ_STREAM:
return AsStream()->Identical(pOther->AsStream());
case PDFOBJ_REFERENCE:
- return AsReference()->Identical(pOther->AsReference());
+ return (((CPDF_Reference*)this)->Identical((CPDF_Reference*)pOther));
}
return FALSE;
}
CPDF_Object* CPDF_Object::GetDirect() const {
- const CPDF_Reference* pRef = AsReference();
- if (!pRef)
- return const_cast<CPDF_Object*>(this);
- if (!pRef->m_pObjList)
- return nullptr;
+ if (m_Type != PDFOBJ_REFERENCE) {
+ return (CPDF_Object*)this;
+ }
+ CPDF_Reference* pRef = (CPDF_Reference*)(void*)this;
+ if (pRef->m_pObjList == NULL) {
+ return NULL;
+ }
return pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum());
}
CPDF_Object* CPDF_Object::Clone(FX_BOOL bDirect) const {
@@ -276,7 +295,7 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect,
return new CPDF_Stream(acc.DetachData(), streamSize, pDict);
}
case PDFOBJ_REFERENCE: {
- const CPDF_Reference* pRef = AsReference();
+ CPDF_Reference* pRef = (CPDF_Reference*)this;
FX_DWORD obj_num = pRef->GetRefObjNum();
if (bDirect && !visited->GetValueAt((void*)(uintptr_t)obj_num)) {
visited->SetAt((void*)(uintptr_t)obj_num, (void*)1);
@@ -361,14 +380,6 @@ const CPDF_Number* CPDF_Object::AsNumber() const {
return IsNumber() ? static_cast<const CPDF_Number*>(this) : nullptr;
}
-CPDF_Reference* CPDF_Object::AsReference() {
- return IsReference() ? static_cast<CPDF_Reference*>(this) : nullptr;
-}
-
-const CPDF_Reference* CPDF_Object::AsReference() const {
- return IsReference() ? static_cast<const CPDF_Reference*>(this) : nullptr;
-}
-
CPDF_Stream* CPDF_Object::AsStream() {
return IsStream() ? static_cast<CPDF_Stream*>(this) : nullptr;
}
@@ -628,9 +639,17 @@ CFX_WideString CPDF_Dictionary::GetUnicodeText(const CFX_ByteStringC& key,
CFX_CharMap* pCharMap) const {
CPDF_Object* p = NULL;
m_Map.Lookup(key, (void*&)p);
- if (CPDF_Reference* pRef = ToReference(p))
- p = pRef->GetDirect();
- return p ? p->GetUnicodeText(pCharMap) : CFX_WideString();
+ if (p) {
+ if (p->GetType() == PDFOBJ_REFERENCE) {
+ p = ((CPDF_Reference*)p)->GetDirect();
+ if (p) {
+ return p->GetUnicodeText(pCharMap);
+ }
+ } else {
+ return p->GetUnicodeText(pCharMap);
+ }
+ }
+ return CFX_WideString();
}
CFX_ByteString CPDF_Dictionary::GetString(const CFX_ByteStringC& key,
const CFX_ByteStringC& def) const {
@@ -702,15 +721,17 @@ CPDF_Stream* CPDF_Dictionary::GetStream(const CFX_ByteStringC& key) const {
CFX_FloatRect CPDF_Dictionary::GetRect(const CFX_ByteStringC& key) const {
CFX_FloatRect rect;
CPDF_Array* pArray = GetArray(key);
- if (pArray)
+ if (pArray) {
rect = pArray->GetRect();
+ }
return rect;
}
CFX_AffineMatrix CPDF_Dictionary::GetMatrix(const CFX_ByteStringC& key) const {
CFX_AffineMatrix matrix;
CPDF_Array* pArray = GetArray(key);
- if (pArray)
+ if (pArray) {
matrix = pArray->GetMatrix();
+ }
return matrix;
}
FX_BOOL CPDF_Dictionary::KeyExist(const CFX_ByteStringC& key) const {
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index 71cd8443d5..b2f7eb6d7e 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -258,9 +258,11 @@ FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess,
}
if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) {
CPDF_Reference* pMetadata =
- ToReference(m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata")));
- if (pMetadata)
+ (CPDF_Reference*)m_pDocument->GetRoot()->GetElement(
+ FX_BSTRC("Metadata"));
+ if (pMetadata && pMetadata->GetType() == PDFOBJ_REFERENCE) {
m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum();
+ }
}
return PDFPARSE_ERROR_SUCCESS;
}
@@ -274,10 +276,12 @@ FX_DWORD CPDF_Parser::SetEncryptHandler() {
if (pEncryptObj) {
if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) {
SetEncryptDictionary(pEncryptDict);
- } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) {
- pEncryptObj = m_pDocument->GetIndirectObject(pRef->GetRefObjNum());
- if (pEncryptObj)
+ } else if (pEncryptObj->GetType() == PDFOBJ_REFERENCE) {
+ pEncryptObj = m_pDocument->GetIndirectObject(
+ ((CPDF_Reference*)pEncryptObj)->GetRefObjNum());
+ if (pEncryptObj) {
SetEncryptDictionary(pEncryptObj->GetDict());
+ }
}
}
if (m_bForceUseSecurityHandler) {
@@ -836,12 +840,12 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
if (m_pTrailer) {
CPDF_Object* pRoot =
pTrailer->GetElement(FX_BSTRC("Root"));
- CPDF_Reference* pRef = ToReference(pRoot);
- if (!pRoot ||
- (pRef &&
+ if (pRoot == NULL ||
+ (pRoot->GetType() == PDFOBJ_REFERENCE &&
(FX_DWORD)m_CrossRef.GetSize() >
- pRef->GetRefObjNum() &&
- m_CrossRef.GetAt(pRef->GetRefObjNum()) != 0)) {
+ ((CPDF_Reference*)pRoot)->GetRefObjNum() &&
+ m_CrossRef.GetAt(((CPDF_Reference*)pRoot)
+ ->GetRefObjNum()) != 0)) {
FX_POSITION pos = pTrailer->GetStartPos();
while (pos) {
CFX_ByteString key;
@@ -1125,21 +1129,27 @@ CPDF_Array* CPDF_Parser::GetIDArray() {
if (!pID)
return nullptr;
- if (CPDF_Reference* pRef = pID->AsReference()) {
- pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum());
+ if (pID->GetType() == PDFOBJ_REFERENCE) {
+ pID = ParseIndirectObject(NULL, ((CPDF_Reference*)pID)->GetRefObjNum());
m_pTrailer->SetAt(FX_BSTRC("ID"), pID);
}
return ToArray(pID);
}
FX_DWORD CPDF_Parser::GetRootObjNum() {
- CPDF_Reference* pRef = ToReference(
- m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Root")) : nullptr);
- return pRef ? pRef->GetRefObjNum() : 0;
+ CPDF_Object* pRef =
+ m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Root")) : NULL;
+ if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) {
+ return 0;
+ }
+ return ((CPDF_Reference*)pRef)->GetRefObjNum();
}
FX_DWORD CPDF_Parser::GetInfoObjNum() {
- CPDF_Reference* pRef = ToReference(
- m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Info")) : nullptr);
- return pRef ? pRef->GetRefObjNum() : 0;
+ CPDF_Object* pRef =
+ m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Info")) : NULL;
+ if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) {
+ return 0;
+ }
+ return ((CPDF_Reference*)pRef)->GetRefObjNum();
}
FX_BOOL CPDF_Parser::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) {
bForm = FALSE;
@@ -1607,9 +1617,11 @@ FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess,
}
}
if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) {
- if (CPDF_Reference* pMetadata = ToReference(
- m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata"))))
- m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum();
+ CPDF_Object* pMetadata =
+ m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata"));
+ if (pMetadata && pMetadata->GetType() == PDFOBJ_REFERENCE) {
+ m_Syntax.m_MetadataObjnum = ((CPDF_Reference*)pMetadata)->GetRefObjNum();
+ }
}
return PDFPARSE_ERROR_SUCCESS;
}
@@ -2362,13 +2374,11 @@ CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict,
FX_DWORD gennum) {
CPDF_Object* pLenObj = pDict->GetElement(FX_BSTRC("Length"));
FX_FILESIZE len = -1;
- CPDF_Reference* pLenObjRef = ToReference(pLenObj);
-
- bool differingObjNum = pLenObjRef && pLenObjRef->GetObjList() &&
- pLenObjRef->GetRefObjNum() != objnum;
- if (pLenObj && differingObjNum)
+ if (pLenObj && ((pLenObj->GetType() != PDFOBJ_REFERENCE) ||
+ ((((CPDF_Reference*)pLenObj)->GetObjList()) &&
+ ((CPDF_Reference*)pLenObj)->GetRefObjNum() != objnum))) {
len = pLenObj->GetInteger();
-
+ }
// Locate the start of stream.
ToNextLine();
FX_FILESIZE streamStartPos = m_Pos;
@@ -3054,7 +3064,7 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail(CFX_PtrArray& obj_array,
}
} break;
case PDFOBJ_REFERENCE: {
- CPDF_Reference* pRef = pObj->AsReference();
+ CPDF_Reference* pRef = (CPDF_Reference*)pObj;
FX_DWORD dwNum = pRef->GetRefObjNum();
FX_FILESIZE offset;
FX_DWORD original_size = GetObjectSize(dwNum, offset);
@@ -3096,10 +3106,13 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail(CFX_PtrArray& obj_array,
int32_t iSize = new_obj_array.GetSize();
for (i = 0; i < iSize; ++i) {
CPDF_Object* pObj = (CPDF_Object*)new_obj_array[i];
- if (CPDF_Reference* pRef = pObj->AsReference()) {
+ int32_t type = pObj->GetType();
+ if (type == PDFOBJ_REFERENCE) {
+ CPDF_Reference* pRef = (CPDF_Reference*)pObj;
FX_DWORD dwNum = pRef->GetRefObjNum();
- if (!m_objnum_array.Find(dwNum))
+ if (!m_objnum_array.Find(dwNum)) {
ret_array.Add(pObj);
+ }
} else {
ret_array.Add(pObj);
}
@@ -3367,37 +3380,37 @@ FX_BOOL CPDF_DataAvail::CheckRoot(IFX_DownloadHints* pHints) {
m_docStatus = PDF_DATAAVAIL_ERROR;
return FALSE;
}
- CPDF_Reference* pRef = ToReference(pDict->GetElement(FX_BSTRC("Pages")));
- if (!pRef) {
+ CPDF_Reference* pRef = (CPDF_Reference*)pDict->GetElement(FX_BSTRC("Pages"));
+ if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) {
m_docStatus = PDF_DATAAVAIL_ERROR;
return FALSE;
}
-
m_PagesObjNum = pRef->GetRefObjNum();
CPDF_Reference* pAcroFormRef =
- ToReference(m_pRoot->GetDict()->GetElement(FX_BSTRC("AcroForm")));
- if (pAcroFormRef) {
+ (CPDF_Reference*)m_pRoot->GetDict()->GetElement(FX_BSTRC("AcroForm"));
+ if (pAcroFormRef && pAcroFormRef->GetType() == PDFOBJ_REFERENCE) {
m_bHaveAcroForm = TRUE;
m_dwAcroFormObjNum = pAcroFormRef->GetRefObjNum();
}
-
if (m_dwInfoObjNum) {
m_docStatus = PDF_DATAAVAIL_INFO;
} else {
- m_docStatus =
- m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE;
+ if (m_bHaveAcroForm) {
+ m_docStatus = PDF_DATAAVAIL_ACROFORM;
+ } else {
+ m_docStatus = PDF_DATAAVAIL_PAGETREE;
+ }
}
return TRUE;
}
FX_BOOL CPDF_DataAvail::PreparePageItem() {
CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
CPDF_Reference* pRef =
- ToReference(pRoot ? pRoot->GetElement(FX_BSTRC("Pages")) : nullptr);
- if (!pRef) {
+ pRoot ? (CPDF_Reference*)pRoot->GetElement(FX_BSTRC("Pages")) : NULL;
+ if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) {
m_docStatus = PDF_DATAAVAIL_ERROR;
return FALSE;
}
-
m_PagesObjNum = pRef->GetRefObjNum();
m_pCurrentParser = (CPDF_Parser*)m_pDocument->GetParser();
m_docStatus = PDF_DATAAVAIL_PAGETREE;
@@ -3430,9 +3443,12 @@ FX_BOOL CPDF_DataAvail::CheckPage(IFX_DownloadHints* pHints) {
CPDF_Array* pArray = pObj->GetArray();
if (pArray) {
int32_t iSize = pArray->GetCount();
+ CPDF_Object* pItem = NULL;
for (int32_t j = 0; j < iSize; ++j) {
- if (CPDF_Reference* pRef = ToReference(pArray->GetElement(j)))
- UnavailObjList.Add(pRef->GetRefObjNum());
+ pItem = pArray->GetElement(j);
+ if (pItem && pItem->GetType() == PDFOBJ_REFERENCE) {
+ UnavailObjList.Add(((CPDF_Reference*)pItem)->GetRefObjNum());
+ }
}
}
}
@@ -3487,14 +3503,17 @@ FX_BOOL CPDF_DataAvail::GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages) {
return TRUE;
}
switch (pKids->GetType()) {
- case PDFOBJ_REFERENCE:
- m_PageObjList.Add(pKids->AsReference()->GetRefObjNum());
- break;
+ case PDFOBJ_REFERENCE: {
+ CPDF_Reference* pKid = (CPDF_Reference*)pKids;
+ m_PageObjList.Add(pKid->GetRefObjNum());
+ } break;
case PDFOBJ_ARRAY: {
CPDF_Array* pKidsArray = pKids->AsArray();
for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) {
- if (CPDF_Reference* pRef = ToReference(pKidsArray->GetElement(i)))
- m_PageObjList.Add(pRef->GetRefObjNum());
+ CPDF_Object* pKid = (CPDF_Object*)pKidsArray->GetElement(i);
+ if (pKid && pKid->GetType() == PDFOBJ_REFERENCE) {
+ m_PageObjList.Add(((CPDF_Reference*)pKid)->GetRefObjNum());
+ }
}
} break;
default:
@@ -3993,7 +4012,7 @@ FX_BOOL CPDF_DataAvail::CheckTrailer(IFX_DownloadHints* pHints) {
CPDF_Dictionary* pTrailerDict = pTrailer->GetDict();
CPDF_Object* pEncrypt = pTrailerDict->GetElement("Encrypt");
- if (ToReference(pEncrypt)) {
+ if (pEncrypt && pEncrypt->GetType() == PDFOBJ_REFERENCE) {
m_docStatus = PDF_DATAAVAIL_LOADALLFILE;
return TRUE;
}
@@ -4072,13 +4091,13 @@ FX_BOOL CPDF_DataAvail::CheckArrayPageNode(FX_DWORD dwPageNo,
pPageNode->m_type = PDF_PAGENODE_PAGES;
for (FX_DWORD i = 0; i < pArray->GetCount(); ++i) {
- CPDF_Reference* pKid = ToReference(pArray->GetElement(i));
- if (!pKid)
+ CPDF_Object* pKid = (CPDF_Object*)pArray->GetElement(i);
+ if (!pKid || pKid->GetType() != PDFOBJ_REFERENCE) {
continue;
-
+ }
CPDF_PageNode* pNode = new CPDF_PageNode();
pPageNode->m_childNode.Add(pNode);
- pNode->m_dwPageNo = pKid->GetRefObjNum();
+ pNode->m_dwPageNo = ((CPDF_Reference*)pKid)->GetRefObjNum();
}
pPages->Release();
return TRUE;
@@ -4122,7 +4141,7 @@ FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo,
}
switch (pKids->GetType()) {
case PDFOBJ_REFERENCE: {
- CPDF_Reference* pKid = pKids->AsReference();
+ CPDF_Reference* pKid = (CPDF_Reference*)pKids;
CPDF_PageNode* pNode = new CPDF_PageNode();
pPageNode->m_childNode.Add(pNode);
pNode->m_dwPageNo = pKid->GetRefObjNum();
@@ -4130,13 +4149,13 @@ FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo,
case PDFOBJ_ARRAY: {
CPDF_Array* pKidsArray = pKids->AsArray();
for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) {
- CPDF_Reference* pKid = ToReference(pKidsArray->GetElement(i));
- if (!pKid)
+ CPDF_Object* pKid = (CPDF_Object*)pKidsArray->GetElement(i);
+ if (!pKid || pKid->GetType() != PDFOBJ_REFERENCE) {
continue;
-
+ }
CPDF_PageNode* pNode = new CPDF_PageNode();
pPageNode->m_childNode.Add(pNode);
- pNode->m_dwPageNo = pKid->GetRefObjNum();
+ pNode->m_dwPageNo = ((CPDF_Reference*)pKid)->GetRefObjNum();
}
} break;
default:
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
index e1e60ecae3..606bd0f569 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
@@ -381,7 +381,8 @@ CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) {
break;
}
case PDFOBJ_REFERENCE: {
- buf << " " << pObj->AsReference()->GetRefObjNum() << FX_BSTRC(" 0 R ");
+ CPDF_Reference* p = (CPDF_Reference*)pObj;
+ buf << " " << p->GetRefObjNum() << FX_BSTRC(" 0 R ");
break;
}
case PDFOBJ_ARRAY: {
diff --git a/core/src/fpdfdoc/doc_form.cpp b/core/src/fpdfdoc/doc_form.cpp
index 3192445d90..8078608883 100644
--- a/core/src/fpdfdoc/doc_form.cpp
+++ b/core/src/fpdfdoc/doc_form.cpp
@@ -1086,12 +1086,13 @@ CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) {
}
pField = new CPDF_FormField(this, pParent);
CPDF_Object* pTObj = pDict->GetElement("T");
- if (ToReference(pTObj)) {
+ if (pTObj && pTObj->GetType() == PDFOBJ_REFERENCE) {
CPDF_Object* pClone = pTObj->Clone(TRUE);
- if (pClone)
+ if (pClone) {
pDict->SetAt("T", pClone);
- else
+ } else {
pDict->SetAtName("T", "");
+ }
}
m_pFieldTree->SetField(csWName, pField);
}
diff --git a/core/src/fpdfdoc/doc_tagged.cpp b/core/src/fpdfdoc/doc_tagged.cpp
index f1877c6573..f74aa7f6f5 100644
--- a/core/src/fpdfdoc/doc_tagged.cpp
+++ b/core/src/fpdfdoc/doc_tagged.cpp
@@ -173,10 +173,10 @@ FX_BOOL CPDF_StructTreeImpl::AddTopLevelNode(CPDF_Dictionary* pDict,
FX_DWORD i;
FX_BOOL bSave = FALSE;
for (i = 0; i < pTopKids->GetCount(); i++) {
- CPDF_Reference* pKidRef = ToReference(pTopKids->GetElement(i));
- if (!pKidRef)
+ CPDF_Object* pKidRef = pTopKids->GetElement(i);
+ if (!pKidRef || pKidRef->GetType() != PDFOBJ_REFERENCE)
continue;
- if (pKidRef->GetRefObjNum() != pDict->GetObjNum())
+ if (((CPDF_Reference*)pKidRef)->GetRefObjNum() != pDict->GetObjNum())
continue;
if (m_Kids[i])
@@ -225,8 +225,8 @@ void CPDF_StructElementImpl::Release() {
void CPDF_StructElementImpl::LoadKids(CPDF_Dictionary* pDict) {
CPDF_Object* pObj = pDict->GetElement(FX_BSTRC("Pg"));
FX_DWORD PageObjNum = 0;
- if (CPDF_Reference* pRef = ToReference(pObj))
- PageObjNum = pRef->GetRefObjNum();
+ if (pObj && pObj->GetType() == PDFOBJ_REFERENCE)
+ PageObjNum = ((CPDF_Reference*)pObj)->GetRefObjNum();
CPDF_Object* pKids = pDict->GetElementValue(FX_BSTRC("K"));
if (!pKids)
@@ -264,18 +264,20 @@ void CPDF_StructElementImpl::LoadKid(FX_DWORD PageObjNum,
if (!pKidDict)
return;
- if (CPDF_Reference* pRef = ToReference(pKidDict->GetElement(FX_BSTRC("Pg"))))
- PageObjNum = pRef->GetRefObjNum();
-
+ CPDF_Object* pPageObj = pKidDict->GetElement(FX_BSTRC("Pg"));
+ if (pPageObj && pPageObj->GetType() == PDFOBJ_REFERENCE) {
+ PageObjNum = ((CPDF_Reference*)pPageObj)->GetRefObjNum();
+ }
CFX_ByteString type = pKidDict->GetString(FX_BSTRC("Type"));
if (type == FX_BSTRC("MCR")) {
if (m_pTree->m_pPage && m_pTree->m_pPage->GetObjNum() != PageObjNum) {
return;
}
pKid->m_Type = CPDF_StructKid::StreamContent;
- if (CPDF_Reference* pRef =
- ToReference(pKidDict->GetElement(FX_BSTRC("Stm")))) {
- pKid->m_StreamContent.m_RefObjNum = pRef->GetRefObjNum();
+ CPDF_Object* pStreamObj = pKidDict->GetElement(FX_BSTRC("Stm"));
+ if (pStreamObj && pStreamObj->GetType() == PDFOBJ_REFERENCE) {
+ pKid->m_StreamContent.m_RefObjNum =
+ ((CPDF_Reference*)pStreamObj)->GetRefObjNum();
} else {
pKid->m_StreamContent.m_RefObjNum = 0;
}
@@ -286,9 +288,9 @@ void CPDF_StructElementImpl::LoadKid(FX_DWORD PageObjNum,
return;
}
pKid->m_Type = CPDF_StructKid::Object;
- if (CPDF_Reference* pObj =
- ToReference(pKidDict->GetElement(FX_BSTRC("Obj")))) {
- pKid->m_Object.m_RefObjNum = pObj->GetRefObjNum();
+ CPDF_Object* pObj = pKidDict->GetElement(FX_BSTRC("Obj"));
+ if (pObj && pObj->GetType() == PDFOBJ_REFERENCE) {
+ pKid->m_Object.m_RefObjNum = ((CPDF_Reference*)pObj)->GetRefObjNum();
} else {
pKid->m_Object.m_RefObjNum = 0;
}