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 <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 if (CPDF_Dictionary* pTrailer = | 832 if (CPDF_Dictionary* pTrailer = |
833 pStream ? pStream->GetDict() : pObj->AsDictionary()) { | 833 pStream ? pStream->GetDict() : pObj->AsDictionary()) { |
834 if (m_pTrailer) { | 834 if (m_pTrailer) { |
835 CPDF_Object* pRoot = pTrailer->GetElement("Root"); | 835 CPDF_Object* pRoot = pTrailer->GetElement("Root"); |
836 CPDF_Reference* pRef = ToReference(pRoot); | 836 CPDF_Reference* pRef = ToReference(pRoot); |
837 if (!pRoot || | 837 if (!pRoot || |
838 (pRef && | 838 (pRef && |
839 (FX_DWORD)m_CrossRef.GetSize() > | 839 (FX_DWORD)m_CrossRef.GetSize() > |
840 pRef->GetRefObjNum() && | 840 pRef->GetRefObjNum() && |
841 m_CrossRef.GetAt(pRef->GetRefObjNum()) != 0)) { | 841 m_CrossRef.GetAt(pRef->GetRefObjNum()) != 0)) { |
842 FX_POSITION pos = pTrailer->GetStartPos(); | 842 for (const auto& it : *pTrailer) { |
843 while (pos) { | 843 const CFX_ByteString& key = it.first; |
844 CFX_ByteString key; | 844 CPDF_Object* pElement = it.second; |
845 CPDF_Object* pElement = | |
846 pTrailer->GetNextElement(pos, key); | |
847 FX_DWORD dwObjNum = | 845 FX_DWORD dwObjNum = |
848 pElement ? pElement->GetObjNum() : 0; | 846 pElement ? pElement->GetObjNum() : 0; |
849 if (dwObjNum) { | 847 if (dwObjNum) { |
850 m_pTrailer->SetAtReference(key, m_pDocument, | 848 m_pTrailer->SetAtReference(key, m_pDocument, |
851 dwObjNum); | 849 dwObjNum); |
852 } else { | 850 } else { |
853 m_pTrailer->SetAt(key, pElement->Clone()); | 851 m_pTrailer->SetAt(key, pElement->Clone()); |
854 } | 852 } |
855 } | 853 } |
856 pObj->Release(); | 854 pObj->Release(); |
(...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2112 continue; | 2110 continue; |
2113 | 2111 |
2114 if (key == "/Contents") | 2112 if (key == "/Contents") |
2115 dwSignValuePos = m_Pos; | 2113 dwSignValuePos = m_Pos; |
2116 | 2114 |
2117 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum); | 2115 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum); |
2118 if (!pObj) | 2116 if (!pObj) |
2119 continue; | 2117 continue; |
2120 | 2118 |
2121 CFX_ByteStringC keyNoSlash(key.c_str() + 1, key.GetLength() - 1); | 2119 CFX_ByteStringC keyNoSlash(key.c_str() + 1, key.GetLength() - 1); |
2122 // TODO(thestig): Remove this conditional once CPDF_Dictionary has a | 2120 pDict->SetAt(keyNoSlash, pObj); |
2123 // better underlying map implementation. | |
2124 if (nKeys < 32) { | |
2125 pDict->SetAt(keyNoSlash, pObj); | |
2126 } else { | |
2127 pDict->AddValue(keyNoSlash, pObj); | |
2128 } | |
2129 } | 2121 } |
2130 | 2122 |
2131 if (IsSignatureDict(pDict.get())) { | 2123 if (IsSignatureDict(pDict.get())) { |
2132 FX_FILESIZE dwSavePos = m_Pos; | 2124 FX_FILESIZE dwSavePos = m_Pos; |
2133 m_Pos = dwSignValuePos; | 2125 m_Pos = dwSignValuePos; |
2134 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, NULL, FALSE); | 2126 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, NULL, FALSE); |
2135 pDict->SetAt("Contents", pObj); | 2127 pDict->SetAt("Contents", pObj); |
2136 m_Pos = dwSavePos; | 2128 m_Pos = dwSavePos; |
2137 } | 2129 } |
2138 if (pContext) { | 2130 if (pContext) { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2265 key = PDF_NameDecode(key); | 2257 key = PDF_NameDecode(key); |
2266 nonstd::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> obj( | 2258 nonstd::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> obj( |
2267 GetObject(pObjList, objnum, gennum)); | 2259 GetObject(pObjList, objnum, gennum)); |
2268 if (!obj) { | 2260 if (!obj) { |
2269 uint8_t ch; | 2261 uint8_t ch; |
2270 while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) { | 2262 while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) { |
2271 } | 2263 } |
2272 return nullptr; | 2264 return nullptr; |
2273 } | 2265 } |
2274 if (key.GetLength() > 1) { | 2266 if (key.GetLength() > 1) { |
2275 pDict->AddValue(CFX_ByteStringC(key.c_str() + 1, key.GetLength() - 1), | 2267 pDict->SetAt(CFX_ByteStringC(key.c_str() + 1, key.GetLength() - 1), |
2276 obj.release()); | 2268 obj.release()); |
2277 } | 2269 } |
2278 } | 2270 } |
2279 if (pContext) { | 2271 if (pContext) { |
2280 pContext->m_DictEnd = m_Pos; | 2272 pContext->m_DictEnd = m_Pos; |
2281 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { | 2273 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { |
2282 return pDict.release(); | 2274 return pDict.release(); |
2283 } | 2275 } |
2284 } | 2276 } |
2285 FX_FILESIZE SavedPos = m_Pos; | 2277 FX_FILESIZE SavedPos = m_Pos; |
2286 FX_BOOL bIsNumber; | 2278 FX_BOOL bIsNumber; |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3017 new_obj_array.Add(pArray->GetElement(k)); | 3009 new_obj_array.Add(pArray->GetElement(k)); |
3018 } | 3010 } |
3019 } break; | 3011 } break; |
3020 case PDFOBJ_STREAM: | 3012 case PDFOBJ_STREAM: |
3021 pObj = pObj->GetDict(); | 3013 pObj = pObj->GetDict(); |
3022 case PDFOBJ_DICTIONARY: { | 3014 case PDFOBJ_DICTIONARY: { |
3023 CPDF_Dictionary* pDict = pObj->GetDict(); | 3015 CPDF_Dictionary* pDict = pObj->GetDict(); |
3024 if (pDict && pDict->GetString("Type") == "Page" && !bParsePage) { | 3016 if (pDict && pDict->GetString("Type") == "Page" && !bParsePage) { |
3025 continue; | 3017 continue; |
3026 } | 3018 } |
3027 FX_POSITION pos = pDict->GetStartPos(); | 3019 for (const auto& it : *pDict) { |
3028 while (pos) { | 3020 const CFX_ByteString& key = it.first; |
3029 CPDF_Object* value; | 3021 CPDF_Object* value = it.second; |
3030 CFX_ByteString key; | |
3031 value = pDict->GetNextElement(pos, key); | |
3032 if (key != "Parent") { | 3022 if (key != "Parent") { |
3033 new_obj_array.Add(value); | 3023 new_obj_array.Add(value); |
3034 } | 3024 } |
3035 } | 3025 } |
3036 } break; | 3026 } break; |
3037 case PDFOBJ_REFERENCE: { | 3027 case PDFOBJ_REFERENCE: { |
3038 CPDF_Reference* pRef = pObj->AsReference(); | 3028 CPDF_Reference* pRef = pObj->AsReference(); |
3039 FX_DWORD dwNum = pRef->GetRefObjNum(); | 3029 FX_DWORD dwNum = pRef->GetRefObjNum(); |
3040 FX_FILESIZE offset; | 3030 FX_FILESIZE offset; |
3041 FX_DWORD size = GetObjectSize(dwNum, offset); | 3031 FX_DWORD size = GetObjectSize(dwNum, offset); |
(...skipping 1942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4984 if (!m_pLinearizedDict) | 4974 if (!m_pLinearizedDict) |
4985 return -1; | 4975 return -1; |
4986 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); | 4976 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); |
4987 if (!pRange) | 4977 if (!pRange) |
4988 return -1; | 4978 return -1; |
4989 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4979 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
4990 if (!pStreamLen) | 4980 if (!pStreamLen) |
4991 return -1; | 4981 return -1; |
4992 return pStreamLen->GetInteger(); | 4982 return pStreamLen->GetInteger(); |
4993 } | 4983 } |
OLD | NEW |