diff options
-rw-r--r-- | core/include/fpdfapi/fpdf_objects.h | 11 | ||||
-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 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_form.cpp | 7 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_tagged.cpp | 30 | ||||
-rw-r--r-- | fpdfsdk/src/fpdf_flatten.cpp | 4 | ||||
-rw-r--r-- | fpdfsdk/src/fpdf_transformpage.cpp | 8 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfppo.cpp | 2 |
12 files changed, 233 insertions, 160 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; } diff --git a/fpdfsdk/src/fpdf_flatten.cpp b/fpdfsdk/src/fpdf_flatten.cpp index 75db8f806d..39441c4aef 100644 --- a/fpdfsdk/src/fpdf_flatten.cpp +++ b/fpdfsdk/src/fpdf_flatten.cpp @@ -444,10 +444,12 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { CFX_ByteString sKey; CPDF_Object* pFirstObj = pAPDic->GetNextElement(pos, sKey); if (pFirstObj) { - if (pFirstObj->IsReference()) + if (pFirstObj->GetType() == PDFOBJ_REFERENCE) pFirstObj = pFirstObj->GetDirect(); + if (!pFirstObj->IsStream()) continue; + pAPStream = pFirstObj->AsStream(); } } diff --git a/fpdfsdk/src/fpdf_transformpage.cpp b/fpdfsdk/src/fpdf_transformpage.cpp index 8a835fb220..20713fe07d 100644 --- a/fpdfsdk/src/fpdf_transformpage.cpp +++ b/fpdfsdk/src/fpdf_transformpage.cpp @@ -135,7 +135,8 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); pContentArray->InsertAt(0, pRef); pContentArray->AddReference(pDoc, pEndStream); - } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { + } else if (pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE) { + CPDF_Reference* pReference = (CPDF_Reference*)pContentObj; CPDF_Object* pDirectObj = pReference->GetDirect(); if (pDirectObj) { if (CPDF_Array* pArray = pDirectObj->AsArray()) { @@ -164,7 +165,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, CPDF_Dictionary* pDict = nullptr; CFX_ByteString key; CPDF_Object* pObj = pPattenDict->GetNextElement(pos, key); - if (pObj->IsReference()) + if (pObj->GetType() == PDFOBJ_REFERENCE) pObj = pObj->GetDirect(); if (pObj->IsDictionary()) @@ -305,7 +306,8 @@ DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page, pContentArray = pArray; CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); pContentArray->InsertAt(0, pRef); - } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { + } else if (pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE) { + CPDF_Reference* pReference = (CPDF_Reference*)pContentObj; CPDF_Object* pDirectObj = pReference->GetDirect(); if (pDirectObj) { if (CPDF_Array* pArray = pDirectObj->AsArray()) { diff --git a/fpdfsdk/src/fpdfppo.cpp b/fpdfsdk/src/fpdfppo.cpp index 6bdd7c5e67..c9df813789 100644 --- a/fpdfsdk/src/fpdfppo.cpp +++ b/fpdfsdk/src/fpdfppo.cpp @@ -207,7 +207,7 @@ FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj, ObjectNumberMap* pObjNumberMap) { switch (pObj->GetType()) { case PDFOBJ_REFERENCE: { - CPDF_Reference* pReference = pObj->AsReference(); + CPDF_Reference* pReference = (CPDF_Reference*)pObj; FX_DWORD newobjnum = GetNewObjId(pDoc, pObjNumberMap, pReference); if (newobjnum == 0) return FALSE; |