OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 void* pResult = | 777 void* pResult = |
778 FXSYS_bsearch(&obj_pos, m_SortedOffset.GetData(), | 778 FXSYS_bsearch(&obj_pos, m_SortedOffset.GetData(), |
779 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), | 779 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), |
780 CompareFileSize); | 780 CompareFileSize); |
781 if (pResult == NULL) { | 781 if (pResult == NULL) { |
782 m_SortedOffset.Add(obj_pos); | 782 m_SortedOffset.Add(obj_pos); |
783 } | 783 } |
784 FX_FILESIZE obj_end = 0; | 784 FX_FILESIZE obj_end = 0; |
785 CPDF_Object* pObject = ParseIndirectObjectAtByStrict( | 785 CPDF_Object* pObject = ParseIndirectObjectAtByStrict( |
786 m_pDocument, obj_pos, objnum, NULL, &obj_end); | 786 m_pDocument, obj_pos, objnum, NULL, &obj_end); |
787 if (pObject) { | 787 if (CPDF_Stream* pStream = ToStream(pObject)) { |
788 int iType = pObject->GetType(); | 788 if (CPDF_Dictionary* pDict = pStream->GetDict()) { |
789 if (iType == PDFOBJ_STREAM) { | 789 if ((pDict->KeyExist(FX_BSTRC("Type"))) && |
790 CPDF_Stream* pStream = (CPDF_Stream*)pObject; | 790 (pDict->GetString(FX_BSTRC("Type")) == |
791 CPDF_Dictionary* pDict = pStream->GetDict(); | 791 FX_BSTRC("XRef") && |
792 if (pDict) { | 792 pDict->KeyExist(FX_BSTRC("Size")))) { |
793 if (pDict->KeyExist(FX_BSTRC("Type"))) { | 793 CPDF_Object* pRoot = pDict->GetElement(FX_BSTRC("Root")); |
794 CFX_ByteString bsValue = | 794 if (pRoot && pRoot->GetDict() && |
795 pDict->GetString(FX_BSTRC("Type")); | 795 pRoot->GetDict()->GetElement(FX_BSTRC("Pages"))) { |
796 if (bsValue == FX_BSTRC("XRef") && | 796 if (m_pTrailer) |
797 pDict->KeyExist(FX_BSTRC("Size"))) { | 797 m_pTrailer->Release(); |
798 CPDF_Object* pRoot = | 798 m_pTrailer = ToDictionary(pDict->Clone()); |
799 pDict->GetElement(FX_BSTRC("Root")); | |
800 if (pRoot && pRoot->GetDict() && | |
801 pRoot->GetDict()->GetElement(FX_BSTRC("Pages"))) { | |
802 if (m_pTrailer) { | |
803 m_pTrailer->Release(); | |
804 } | |
805 m_pTrailer = ToDictionary(pDict->Clone()); | |
806 } | |
807 } | 799 } |
808 } | 800 } |
809 } | |
810 } | 801 } |
811 } | 802 } |
812 FX_FILESIZE offset = 0; | 803 FX_FILESIZE offset = 0; |
813 m_Syntax.RestorePos(obj_pos); | 804 m_Syntax.RestorePos(obj_pos); |
814 offset = m_Syntax.FindTag(FX_BSTRC("obj"), 0); | 805 offset = m_Syntax.FindTag(FX_BSTRC("obj"), 0); |
815 if (offset == -1) { | 806 if (offset == -1) { |
816 offset = 0; | 807 offset = 0; |
817 } else { | 808 } else { |
818 offset += 3; | 809 offset += 3; |
819 } | 810 } |
(...skipping 28 matching lines...) Expand all Loading... |
848 break; | 839 break; |
849 } | 840 } |
850 break; | 841 break; |
851 case 7: | 842 case 7: |
852 if (inside_index == 7) { | 843 if (inside_index == 7) { |
853 if (PDF_CharType[byte] == 'W' || PDF_CharType[byte] == 'D') { | 844 if (PDF_CharType[byte] == 'W' || PDF_CharType[byte] == 'D') { |
854 last_trailer = pos + i - 7; | 845 last_trailer = pos + i - 7; |
855 m_Syntax.RestorePos(pos + i - m_Syntax.m_HeaderOffset); | 846 m_Syntax.RestorePos(pos + i - m_Syntax.m_HeaderOffset); |
856 CPDF_Object* pObj = m_Syntax.GetObject(m_pDocument, 0, 0, 0); | 847 CPDF_Object* pObj = m_Syntax.GetObject(m_pDocument, 0, 0, 0); |
857 if (pObj) { | 848 if (pObj) { |
858 if (!pObj->IsDictionary() && pObj->GetType() != PDFOBJ_STREAM) { | 849 if (!pObj->IsDictionary() && !pObj->AsStream()) { |
859 pObj->Release(); | 850 pObj->Release(); |
860 } else { | 851 } else { |
861 CPDF_Dictionary* pTrailer = NULL; | 852 CPDF_Stream* pStream = pObj->AsStream(); |
862 if (pObj->GetType() == PDFOBJ_STREAM) { | 853 if (CPDF_Dictionary* pTrailer = |
863 pTrailer = ((CPDF_Stream*)pObj)->GetDict(); | 854 pStream ? pStream->GetDict() : pObj->AsDictionary()) { |
864 } else { | |
865 pTrailer = pObj->AsDictionary(); | |
866 } | |
867 if (pTrailer) { | |
868 if (m_pTrailer) { | 855 if (m_pTrailer) { |
869 CPDF_Object* pRoot = | 856 CPDF_Object* pRoot = |
870 pTrailer->GetElement(FX_BSTRC("Root")); | 857 pTrailer->GetElement(FX_BSTRC("Root")); |
871 if (pRoot == NULL || | 858 if (pRoot == NULL || |
872 (pRoot->GetType() == PDFOBJ_REFERENCE && | 859 (pRoot->GetType() == PDFOBJ_REFERENCE && |
873 (FX_DWORD)m_CrossRef.GetSize() > | 860 (FX_DWORD)m_CrossRef.GetSize() > |
874 ((CPDF_Reference*)pRoot)->GetRefObjNum() && | 861 ((CPDF_Reference*)pRoot)->GetRefObjNum() && |
875 m_CrossRef.GetAt(((CPDF_Reference*)pRoot) | 862 m_CrossRef.GetAt(((CPDF_Reference*)pRoot) |
876 ->GetRefObjNum()) != 0)) { | 863 ->GetRefObjNum()) != 0)) { |
877 FX_POSITION pos = pTrailer->GetStartPos(); | 864 FX_POSITION pos = pTrailer->GetStartPos(); |
878 while (pos) { | 865 while (pos) { |
879 CFX_ByteString key; | 866 CFX_ByteString key; |
880 CPDF_Object* pObj = | 867 CPDF_Object* pObj = |
881 pTrailer->GetNextElement(pos, key); | 868 pTrailer->GetNextElement(pos, key); |
882 m_pTrailer->SetAt(key, pObj->Clone(), m_pDocument); | 869 m_pTrailer->SetAt(key, pObj->Clone(), m_pDocument); |
883 } | 870 } |
884 pObj->Release(); | 871 pObj->Release(); |
885 } else { | 872 } else { |
886 pObj->Release(); | 873 pObj->Release(); |
887 } | 874 } |
888 } else { | 875 } else { |
889 if (pObj->GetType() == PDFOBJ_STREAM) { | 876 if (pObj->IsStream()) { |
890 m_pTrailer = ToDictionary(pTrailer->Clone()); | 877 m_pTrailer = ToDictionary(pTrailer->Clone()); |
891 pObj->Release(); | 878 pObj->Release(); |
892 } else { | 879 } else { |
893 m_pTrailer = pTrailer; | 880 m_pTrailer = pTrailer; |
894 } | 881 } |
895 FX_FILESIZE dwSavePos = m_Syntax.SavePos(); | 882 FX_FILESIZE dwSavePos = m_Syntax.SavePos(); |
896 CFX_ByteString strWord = m_Syntax.GetKeyword(); | 883 CFX_ByteString strWord = m_Syntax.GetKeyword(); |
897 if (!strWord.Compare(FX_BSTRC("startxref"))) { | 884 if (!strWord.Compare(FX_BSTRC("startxref"))) { |
898 FX_BOOL bNumber = FALSE; | 885 FX_BOOL bNumber = FALSE; |
899 CFX_ByteString bsOffset = m_Syntax.GetNextWord(bNumber); | 886 CFX_ByteString bsOffset = m_Syntax.GetNextWord(bNumber); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 if (pResult == NULL) { | 985 if (pResult == NULL) { |
999 m_SortedOffset.Add(offset); | 986 m_SortedOffset.Add(offset); |
1000 } | 987 } |
1001 FX_Free(buffer); | 988 FX_Free(buffer); |
1002 return TRUE; | 989 return TRUE; |
1003 } | 990 } |
1004 | 991 |
1005 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE pos, | 992 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE pos, |
1006 FX_FILESIZE& prev, | 993 FX_FILESIZE& prev, |
1007 FX_BOOL bMainXRef) { | 994 FX_BOOL bMainXRef) { |
1008 CPDF_Stream* pStream = | 995 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, pos, 0, nullptr); |
1009 (CPDF_Stream*)ParseIndirectObjectAt(m_pDocument, pos, 0, NULL); | 996 if (!pObject) |
1010 if (!pStream) { | |
1011 return FALSE; | 997 return FALSE; |
1012 } | 998 |
1013 if (m_pDocument) { | 999 if (m_pDocument) { |
1014 CPDF_Dictionary* pDict = m_pDocument->GetRoot(); | 1000 CPDF_Dictionary* pDict = m_pDocument->GetRoot(); |
1015 if (!pDict || pDict->GetObjNum() != pStream->m_ObjNum) { | 1001 if (!pDict || pDict->GetObjNum() != pObject->m_ObjNum) { |
1016 m_pDocument->InsertIndirectObject(pStream->m_ObjNum, pStream); | 1002 m_pDocument->InsertIndirectObject(pObject->m_ObjNum, pObject); |
1017 } else { | 1003 } else { |
1018 if (pStream->GetType() == PDFOBJ_STREAM) { | 1004 if (pObject->IsStream()) |
1019 pStream->Release(); | 1005 pObject->Release(); |
1020 } | |
1021 return FALSE; | 1006 return FALSE; |
1022 } | 1007 } |
1023 } | 1008 } |
1024 if (pStream->GetType() != PDFOBJ_STREAM) { | 1009 |
| 1010 CPDF_Stream* pStream = pObject->AsStream(); |
| 1011 if (!pStream) |
1025 return FALSE; | 1012 return FALSE; |
1026 } | 1013 |
1027 prev = pStream->GetDict()->GetInteger(FX_BSTRC("Prev")); | 1014 prev = pStream->GetDict()->GetInteger(FX_BSTRC("Prev")); |
1028 int32_t size = pStream->GetDict()->GetInteger(FX_BSTRC("Size")); | 1015 int32_t size = pStream->GetDict()->GetInteger(FX_BSTRC("Size")); |
1029 if (size < 0) { | 1016 if (size < 0) { |
1030 pStream->Release(); | 1017 pStream->Release(); |
1031 return FALSE; | 1018 return FALSE; |
1032 } | 1019 } |
1033 if (bMainXRef) { | 1020 if (bMainXRef) { |
1034 m_pTrailer = ToDictionary(pStream->GetDict()->Clone()); | 1021 m_pTrailer = ToDictionary(pStream->GetDict()->Clone()); |
1035 m_CrossRef.SetSize(size); | 1022 m_CrossRef.SetSize(size); |
1036 if (m_V5Type.SetSize(size)) { | 1023 if (m_V5Type.SetSize(size)) { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 FX_DWORD thisoff = syntax.GetDirectNum(); | 1225 FX_DWORD thisoff = syntax.GetDirectNum(); |
1239 if (thisnum == objnum) { | 1226 if (thisnum == objnum) { |
1240 syntax.RestorePos(offset + thisoff); | 1227 syntax.RestorePos(offset + thisoff); |
1241 return syntax.GetObject(pObjList, 0, 0, pContext); | 1228 return syntax.GetObject(pObjList, 0, 0, pContext); |
1242 } | 1229 } |
1243 } | 1230 } |
1244 return nullptr; | 1231 return nullptr; |
1245 } | 1232 } |
1246 | 1233 |
1247 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) { | 1234 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) { |
1248 CPDF_StreamAcc* pStreamAcc = NULL; | 1235 CPDF_StreamAcc* pStreamAcc = nullptr; |
1249 if (m_ObjectStreamMap.Lookup((void*)(uintptr_t)objnum, (void*&)pStreamAcc)) { | 1236 if (m_ObjectStreamMap.Lookup((void*)(uintptr_t)objnum, (void*&)pStreamAcc)) |
1250 return pStreamAcc; | 1237 return pStreamAcc; |
1251 } | 1238 |
1252 const CPDF_Stream* pStream = | 1239 const CPDF_Stream* pStream = |
1253 m_pDocument ? (CPDF_Stream*)m_pDocument->GetIndirectObject(objnum) : NULL; | 1240 ToStream(m_pDocument ? m_pDocument->GetIndirectObject(objnum) : nullptr); |
1254 if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM) { | 1241 if (!pStream) |
1255 return NULL; | 1242 return nullptr; |
1256 } | 1243 |
1257 pStreamAcc = new CPDF_StreamAcc; | 1244 pStreamAcc = new CPDF_StreamAcc; |
1258 pStreamAcc->LoadAllData(pStream); | 1245 pStreamAcc->LoadAllData(pStream); |
1259 m_ObjectStreamMap.SetAt((void*)(uintptr_t)objnum, pStreamAcc); | 1246 m_ObjectStreamMap.SetAt((void*)(uintptr_t)objnum, pStreamAcc); |
1260 return pStreamAcc; | 1247 return pStreamAcc; |
1261 } | 1248 } |
1262 FX_FILESIZE CPDF_Parser::GetObjectSize(FX_DWORD objnum) { | 1249 FX_FILESIZE CPDF_Parser::GetObjectSize(FX_DWORD objnum) { |
1263 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { | 1250 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { |
1264 return 0; | 1251 return 0; |
1265 } | 1252 } |
1266 if (m_V5Type[objnum] == 2) { | 1253 if (m_V5Type[objnum] == 2) { |
(...skipping 3348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4615 return FALSE; | 4602 return FALSE; |
4616 } | 4603 } |
4617 CPDF_PageNode::~CPDF_PageNode() { | 4604 CPDF_PageNode::~CPDF_PageNode() { |
4618 int32_t iSize = m_childNode.GetSize(); | 4605 int32_t iSize = m_childNode.GetSize(); |
4619 for (int32_t i = 0; i < iSize; ++i) { | 4606 for (int32_t i = 0; i < iSize; ++i) { |
4620 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; | 4607 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; |
4621 delete pNode; | 4608 delete pNode; |
4622 } | 4609 } |
4623 m_childNode.RemoveAll(); | 4610 m_childNode.RemoveAll(); |
4624 } | 4611 } |
OLD | NEW |