diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2015-10-26 13:02:07 -0400 |
---|---|---|
committer | Dan Sinclair <dsinclair@chromium.org> | 2015-10-26 13:02:07 -0400 |
commit | 7e155865c90cc1115cc7193b7646a341d8f9093e (patch) | |
tree | 44e4351192f0af909671df95a1aac16a1609f750 /core/src/fpdfapi | |
parent | 9024e026dae1af064b8467bb0f62278417fb82d1 (diff) | |
download | pdfium-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/src/fpdfapi')
-rw-r--r-- | core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp | 20 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 53 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp | 13 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp | 107 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp | 135 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp | 3 |
6 files changed, 204 insertions, 127 deletions
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: { |