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 "core/include/fpdfapi/fpdf_parser.h" | 7 #include "core/include/fpdfapi/fpdf_parser.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 } else { | 862 } else { |
863 CPDF_Stream* pStream = pObj->AsStream(); | 863 CPDF_Stream* pStream = pObj->AsStream(); |
864 if (CPDF_Dictionary* pTrailer = | 864 if (CPDF_Dictionary* pTrailer = |
865 pStream ? pStream->GetDict() : pObj->AsDictionary()) { | 865 pStream ? pStream->GetDict() : pObj->AsDictionary()) { |
866 if (m_pTrailer) { | 866 if (m_pTrailer) { |
867 CPDF_Object* pRoot = pTrailer->GetElement("Root"); | 867 CPDF_Object* pRoot = pTrailer->GetElement("Root"); |
868 CPDF_Reference* pRef = ToReference(pRoot); | 868 CPDF_Reference* pRef = ToReference(pRoot); |
869 if (!pRoot || | 869 if (!pRoot || |
870 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && | 870 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && |
871 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { | 871 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { |
872 FX_POSITION trailer_pos = pTrailer->GetStartPos(); | 872 for (const auto& it : *pTrailer) { |
873 while (trailer_pos) { | 873 const CFX_ByteString& key = it.first; |
874 CFX_ByteString key; | 874 CPDF_Object* pElement = it.second; |
875 CPDF_Object* pElement = | |
876 pTrailer->GetNextElement(trailer_pos, key); | |
877 FX_DWORD dwObjNum = | 875 FX_DWORD dwObjNum = |
878 pElement ? pElement->GetObjNum() : 0; | 876 pElement ? pElement->GetObjNum() : 0; |
879 if (dwObjNum) { | 877 if (dwObjNum) { |
880 m_pTrailer->SetAtReference(key, m_pDocument, | 878 m_pTrailer->SetAtReference(key, m_pDocument, |
881 dwObjNum); | 879 dwObjNum); |
882 } else { | 880 } else { |
883 m_pTrailer->SetAt(key, pElement->Clone()); | 881 m_pTrailer->SetAt(key, pElement->Clone()); |
884 } | 882 } |
885 } | 883 } |
886 pObj->Release(); | 884 pObj->Release(); |
(...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2155 continue; | 2153 continue; |
2156 | 2154 |
2157 if (key == "/Contents") | 2155 if (key == "/Contents") |
2158 dwSignValuePos = m_Pos; | 2156 dwSignValuePos = m_Pos; |
2159 | 2157 |
2160 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, nullptr, true); | 2158 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, nullptr, true); |
2161 if (!pObj) | 2159 if (!pObj) |
2162 continue; | 2160 continue; |
2163 | 2161 |
2164 CFX_ByteStringC keyNoSlash(key.c_str() + 1, key.GetLength() - 1); | 2162 CFX_ByteStringC keyNoSlash(key.c_str() + 1, key.GetLength() - 1); |
2165 // TODO(thestig): Remove this conditional once CPDF_Dictionary has a | 2163 pDict->SetAt(keyNoSlash, pObj); |
2166 // better underlying map implementation. | |
2167 if (nKeys < 32) { | |
2168 pDict->SetAt(keyNoSlash, pObj); | |
2169 } else { | |
2170 pDict->AddValue(keyNoSlash, pObj); | |
2171 } | |
2172 } | 2164 } |
2173 | 2165 |
2174 if (IsSignatureDict(pDict.get())) { | 2166 if (IsSignatureDict(pDict.get())) { |
2175 FX_FILESIZE dwSavePos = m_Pos; | 2167 FX_FILESIZE dwSavePos = m_Pos; |
2176 m_Pos = dwSignValuePos; | 2168 m_Pos = dwSignValuePos; |
2177 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, nullptr, FALSE); | 2169 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, nullptr, FALSE); |
2178 pDict->SetAt("Contents", pObj); | 2170 pDict->SetAt("Contents", pObj); |
2179 m_Pos = dwSavePos; | 2171 m_Pos = dwSavePos; |
2180 } | 2172 } |
2181 if (pContext) { | 2173 if (pContext) { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2308 key = PDF_NameDecode(key); | 2300 key = PDF_NameDecode(key); |
2309 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> obj( | 2301 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> obj( |
2310 GetObject(pObjList, objnum, gennum, nullptr, true)); | 2302 GetObject(pObjList, objnum, gennum, nullptr, true)); |
2311 if (!obj) { | 2303 if (!obj) { |
2312 uint8_t ch; | 2304 uint8_t ch; |
2313 while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) { | 2305 while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) { |
2314 } | 2306 } |
2315 return nullptr; | 2307 return nullptr; |
2316 } | 2308 } |
2317 if (key.GetLength() > 1) { | 2309 if (key.GetLength() > 1) { |
2318 pDict->AddValue(CFX_ByteStringC(key.c_str() + 1, key.GetLength() - 1), | 2310 pDict->SetAt(CFX_ByteStringC(key.c_str() + 1, key.GetLength() - 1), |
2319 obj.release()); | 2311 obj.release()); |
2320 } | 2312 } |
2321 } | 2313 } |
2322 if (pContext) { | 2314 if (pContext) { |
2323 pContext->m_DictEnd = m_Pos; | 2315 pContext->m_DictEnd = m_Pos; |
2324 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { | 2316 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { |
2325 return pDict.release(); | 2317 return pDict.release(); |
2326 } | 2318 } |
2327 } | 2319 } |
2328 FX_FILESIZE SavedPos = m_Pos; | 2320 FX_FILESIZE SavedPos = m_Pos; |
2329 CFX_ByteString nextword = GetNextWord(nullptr); | 2321 CFX_ByteString nextword = GetNextWord(nullptr); |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3051 new_obj_array.Add(pArray->GetElement(k)); | 3043 new_obj_array.Add(pArray->GetElement(k)); |
3052 } | 3044 } |
3053 } break; | 3045 } break; |
3054 case PDFOBJ_STREAM: | 3046 case PDFOBJ_STREAM: |
3055 pObj = pObj->GetDict(); | 3047 pObj = pObj->GetDict(); |
3056 case PDFOBJ_DICTIONARY: { | 3048 case PDFOBJ_DICTIONARY: { |
3057 CPDF_Dictionary* pDict = pObj->GetDict(); | 3049 CPDF_Dictionary* pDict = pObj->GetDict(); |
3058 if (pDict && pDict->GetString("Type") == "Page" && !bParsePage) { | 3050 if (pDict && pDict->GetString("Type") == "Page" && !bParsePage) { |
3059 continue; | 3051 continue; |
3060 } | 3052 } |
3061 FX_POSITION pos = pDict->GetStartPos(); | 3053 for (const auto& it : *pDict) { |
3062 while (pos) { | 3054 const CFX_ByteString& key = it.first; |
3063 CPDF_Object* value; | 3055 CPDF_Object* value = it.second; |
3064 CFX_ByteString key; | |
3065 value = pDict->GetNextElement(pos, key); | |
3066 if (key != "Parent") { | 3056 if (key != "Parent") { |
3067 new_obj_array.Add(value); | 3057 new_obj_array.Add(value); |
3068 } | 3058 } |
3069 } | 3059 } |
3070 } break; | 3060 } break; |
3071 case PDFOBJ_REFERENCE: { | 3061 case PDFOBJ_REFERENCE: { |
3072 CPDF_Reference* pRef = pObj->AsReference(); | 3062 CPDF_Reference* pRef = pObj->AsReference(); |
3073 FX_DWORD dwNum = pRef->GetRefObjNum(); | 3063 FX_DWORD dwNum = pRef->GetRefObjNum(); |
3074 FX_FILESIZE offset; | 3064 FX_FILESIZE offset; |
3075 FX_DWORD size = GetObjectSize(dwNum, offset); | 3065 FX_DWORD size = GetObjectSize(dwNum, offset); |
(...skipping 1915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4991 if (!m_pLinearizedDict) | 4981 if (!m_pLinearizedDict) |
4992 return -1; | 4982 return -1; |
4993 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); | 4983 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); |
4994 if (!pRange) | 4984 if (!pRange) |
4995 return -1; | 4985 return -1; |
4996 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4986 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
4997 if (!pStreamLen) | 4987 if (!pStreamLen) |
4998 return -1; | 4988 return -1; |
4999 return pStreamLen->GetInteger(); | 4989 return pStreamLen->GetInteger(); |
5000 } | 4990 } |
OLD | NEW |