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 "parser_int.h" | 7 #include "parser_int.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 } else { | 846 } else { |
847 CPDF_Stream* pStream = pObj->AsStream(); | 847 CPDF_Stream* pStream = pObj->AsStream(); |
848 if (CPDF_Dictionary* pTrailer = | 848 if (CPDF_Dictionary* pTrailer = |
849 pStream ? pStream->GetDict() : pObj->AsDictionary()) { | 849 pStream ? pStream->GetDict() : pObj->AsDictionary()) { |
850 if (m_pTrailer) { | 850 if (m_pTrailer) { |
851 CPDF_Object* pRoot = pTrailer->GetElement("Root"); | 851 CPDF_Object* pRoot = pTrailer->GetElement("Root"); |
852 CPDF_Reference* pRef = ToReference(pRoot); | 852 CPDF_Reference* pRef = ToReference(pRoot); |
853 if (!pRoot || | 853 if (!pRoot || |
854 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && | 854 (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && |
855 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { | 855 m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { |
856 FX_POSITION trailer_pos = pTrailer->GetStartPos(); | 856 for (const auto& it : *pTrailer) { |
857 while (trailer_pos) { | 857 const CFX_ByteString& key = it.first; |
858 CFX_ByteString key; | 858 CPDF_Object* pElement = it.second; |
859 CPDF_Object* pElement = | |
860 pTrailer->GetNextElement(trailer_pos, key); | |
861 FX_DWORD dwObjNum = | 859 FX_DWORD dwObjNum = |
862 pElement ? pElement->GetObjNum() : 0; | 860 pElement ? pElement->GetObjNum() : 0; |
863 if (dwObjNum) { | 861 if (dwObjNum) { |
864 m_pTrailer->SetAtReference(key, m_pDocument, | 862 m_pTrailer->SetAtReference(key, m_pDocument, |
865 dwObjNum); | 863 dwObjNum); |
866 } else { | 864 } else { |
867 m_pTrailer->SetAt(key, pElement->Clone()); | 865 m_pTrailer->SetAt(key, pElement->Clone()); |
868 } | 866 } |
869 } | 867 } |
870 pObj->Release(); | 868 pObj->Release(); |
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2134 continue; | 2132 continue; |
2135 | 2133 |
2136 if (key == "/Contents") | 2134 if (key == "/Contents") |
2137 dwSignValuePos = m_Pos; | 2135 dwSignValuePos = m_Pos; |
2138 | 2136 |
2139 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, nullptr, true); | 2137 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, nullptr, true); |
2140 if (!pObj) | 2138 if (!pObj) |
2141 continue; | 2139 continue; |
2142 | 2140 |
2143 CFX_ByteStringC keyNoSlash(key.c_str() + 1, key.GetLength() - 1); | 2141 CFX_ByteStringC keyNoSlash(key.c_str() + 1, key.GetLength() - 1); |
2144 // TODO(thestig): Remove this conditional once CPDF_Dictionary has a | 2142 pDict->SetAt(keyNoSlash, pObj); |
2145 // better underlying map implementation. | |
2146 if (nKeys < 32) { | |
2147 pDict->SetAt(keyNoSlash, pObj); | |
2148 } else { | |
2149 pDict->AddValue(keyNoSlash, pObj); | |
2150 } | |
2151 } | 2143 } |
2152 | 2144 |
2153 if (IsSignatureDict(pDict.get())) { | 2145 if (IsSignatureDict(pDict.get())) { |
2154 FX_FILESIZE dwSavePos = m_Pos; | 2146 FX_FILESIZE dwSavePos = m_Pos; |
2155 m_Pos = dwSignValuePos; | 2147 m_Pos = dwSignValuePos; |
2156 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, nullptr, FALSE); | 2148 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, nullptr, FALSE); |
2157 pDict->SetAt("Contents", pObj); | 2149 pDict->SetAt("Contents", pObj); |
2158 m_Pos = dwSavePos; | 2150 m_Pos = dwSavePos; |
2159 } | 2151 } |
2160 if (pContext) { | 2152 if (pContext) { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2287 key = PDF_NameDecode(key); | 2279 key = PDF_NameDecode(key); |
2288 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> obj( | 2280 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> obj( |
2289 GetObject(pObjList, objnum, gennum, nullptr, true)); | 2281 GetObject(pObjList, objnum, gennum, nullptr, true)); |
2290 if (!obj) { | 2282 if (!obj) { |
2291 uint8_t ch; | 2283 uint8_t ch; |
2292 while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) { | 2284 while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) { |
2293 } | 2285 } |
2294 return nullptr; | 2286 return nullptr; |
2295 } | 2287 } |
2296 if (key.GetLength() > 1) { | 2288 if (key.GetLength() > 1) { |
2297 pDict->AddValue(CFX_ByteStringC(key.c_str() + 1, key.GetLength() - 1), | 2289 pDict->SetAt(CFX_ByteStringC(key.c_str() + 1, key.GetLength() - 1), |
2298 obj.release()); | 2290 obj.release()); |
2299 } | 2291 } |
2300 } | 2292 } |
2301 if (pContext) { | 2293 if (pContext) { |
2302 pContext->m_DictEnd = m_Pos; | 2294 pContext->m_DictEnd = m_Pos; |
2303 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { | 2295 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { |
2304 return pDict.release(); | 2296 return pDict.release(); |
2305 } | 2297 } |
2306 } | 2298 } |
2307 FX_FILESIZE SavedPos = m_Pos; | 2299 FX_FILESIZE SavedPos = m_Pos; |
2308 CFX_ByteString nextword = GetNextWord(nullptr); | 2300 CFX_ByteString nextword = GetNextWord(nullptr); |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3031 new_obj_array.Add(pArray->GetElement(k)); | 3023 new_obj_array.Add(pArray->GetElement(k)); |
3032 } | 3024 } |
3033 } break; | 3025 } break; |
3034 case PDFOBJ_STREAM: | 3026 case PDFOBJ_STREAM: |
3035 pObj = pObj->GetDict(); | 3027 pObj = pObj->GetDict(); |
3036 case PDFOBJ_DICTIONARY: { | 3028 case PDFOBJ_DICTIONARY: { |
3037 CPDF_Dictionary* pDict = pObj->GetDict(); | 3029 CPDF_Dictionary* pDict = pObj->GetDict(); |
3038 if (pDict && pDict->GetString("Type") == "Page" && !bParsePage) { | 3030 if (pDict && pDict->GetString("Type") == "Page" && !bParsePage) { |
3039 continue; | 3031 continue; |
3040 } | 3032 } |
3041 FX_POSITION pos = pDict->GetStartPos(); | 3033 for (const auto& it : *pDict) { |
3042 while (pos) { | 3034 const CFX_ByteString& key = it.first; |
3043 CPDF_Object* value; | 3035 CPDF_Object* value = it.second; |
3044 CFX_ByteString key; | |
3045 value = pDict->GetNextElement(pos, key); | |
3046 if (key != "Parent") { | 3036 if (key != "Parent") { |
3047 new_obj_array.Add(value); | 3037 new_obj_array.Add(value); |
3048 } | 3038 } |
3049 } | 3039 } |
3050 } break; | 3040 } break; |
3051 case PDFOBJ_REFERENCE: { | 3041 case PDFOBJ_REFERENCE: { |
3052 CPDF_Reference* pRef = pObj->AsReference(); | 3042 CPDF_Reference* pRef = pObj->AsReference(); |
3053 FX_DWORD dwNum = pRef->GetRefObjNum(); | 3043 FX_DWORD dwNum = pRef->GetRefObjNum(); |
3054 FX_FILESIZE offset; | 3044 FX_FILESIZE offset; |
3055 FX_DWORD size = GetObjectSize(dwNum, offset); | 3045 FX_DWORD size = GetObjectSize(dwNum, offset); |
(...skipping 1913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4969 if (!m_pLinearizedDict) | 4959 if (!m_pLinearizedDict) |
4970 return -1; | 4960 return -1; |
4971 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); | 4961 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); |
4972 if (!pRange) | 4962 if (!pRange) |
4973 return -1; | 4963 return -1; |
4974 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4964 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
4975 if (!pStreamLen) | 4965 if (!pStreamLen) |
4976 return -1; | 4966 return -1; |
4977 return pStreamLen->GetInteger(); | 4967 return pStreamLen->GetInteger(); |
4978 } | 4968 } |
OLD | NEW |