| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 m_Syntax.m_pFileAccess = NULL; | 134 m_Syntax.m_pFileAccess = NULL; |
| 135 } | 135 } |
| 136 FX_POSITION pos = m_ObjectStreamMap.GetStartPosition(); | 136 FX_POSITION pos = m_ObjectStreamMap.GetStartPosition(); |
| 137 while (pos) { | 137 while (pos) { |
| 138 void* objnum; | 138 void* objnum; |
| 139 CPDF_StreamAcc* pStream; | 139 CPDF_StreamAcc* pStream; |
| 140 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream); | 140 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream); |
| 141 delete pStream; | 141 delete pStream; |
| 142 } | 142 } |
| 143 m_ObjectStreamMap.RemoveAll(); | 143 m_ObjectStreamMap.RemoveAll(); |
| 144 m_ObjCache.clear(); |
| 145 |
| 144 m_SortedOffset.RemoveAll(); | 146 m_SortedOffset.RemoveAll(); |
| 145 m_CrossRef.RemoveAll(); | 147 m_CrossRef.RemoveAll(); |
| 146 m_V5Type.RemoveAll(); | 148 m_V5Type.RemoveAll(); |
| 147 m_ObjVersion.RemoveAll(); | 149 m_ObjVersion.RemoveAll(); |
| 148 int32_t iLen = m_Trailers.GetSize(); | 150 int32_t iLen = m_Trailers.GetSize(); |
| 149 for (int32_t i = 0; i < iLen; ++i) { | 151 for (int32_t i = 0; i < iLen; ++i) { |
| 150 if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i)) | 152 if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i)) |
| 151 trailer->Release(); | 153 trailer->Release(); |
| 152 } | 154 } |
| 153 m_Trailers.RemoveAll(); | 155 m_Trailers.RemoveAll(); |
| (...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 return nullptr; | 1195 return nullptr; |
| 1194 | 1196 |
| 1195 CPDF_StreamAcc* pObjStream = GetObjectStream((FX_DWORD)m_CrossRef[objnum]); | 1197 CPDF_StreamAcc* pObjStream = GetObjectStream((FX_DWORD)m_CrossRef[objnum]); |
| 1196 if (!pObjStream) | 1198 if (!pObjStream) |
| 1197 return nullptr; | 1199 return nullptr; |
| 1198 | 1200 |
| 1199 ScopedFileStream file(FX_CreateMemoryStream( | 1201 ScopedFileStream file(FX_CreateMemoryStream( |
| 1200 (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), FALSE)); | 1202 (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), FALSE)); |
| 1201 CPDF_SyntaxParser syntax; | 1203 CPDF_SyntaxParser syntax; |
| 1202 syntax.InitParser(file.get(), 0); | 1204 syntax.InitParser(file.get(), 0); |
| 1203 int32_t offset = GetStreamFirst(pObjStream); | 1205 const int32_t offset = GetStreamFirst(pObjStream); |
| 1204 for (int32_t i = GetStreamNCount(pObjStream); i > 0; --i) { | 1206 |
| 1205 FX_DWORD thisnum = syntax.GetDirectNum(); | 1207 // Read object numbers from |pObjStream| into a cache. |
| 1206 FX_DWORD thisoff = syntax.GetDirectNum(); | 1208 if (m_ObjCache.find(pObjStream) == m_ObjCache.end()) { |
| 1207 if (thisnum == objnum) { | 1209 for (int32_t i = GetStreamNCount(pObjStream); i > 0; --i) { |
| 1208 syntax.RestorePos(offset + thisoff); | 1210 FX_DWORD thisnum = syntax.GetDirectNum(); |
| 1209 return syntax.GetObject(pObjList, 0, 0, pContext); | 1211 FX_DWORD thisoff = syntax.GetDirectNum(); |
| 1212 m_ObjCache[pObjStream][thisnum] = thisoff; |
| 1210 } | 1213 } |
| 1211 } | 1214 } |
| 1212 return nullptr; | 1215 |
| 1216 const auto it = m_ObjCache[pObjStream].find(objnum); |
| 1217 if (it == m_ObjCache[pObjStream].end()) |
| 1218 return nullptr; |
| 1219 |
| 1220 syntax.RestorePos(offset + it->second); |
| 1221 return syntax.GetObject(pObjList, 0, 0, pContext); |
| 1213 } | 1222 } |
| 1214 | 1223 |
| 1215 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) { | 1224 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) { |
| 1216 CPDF_StreamAcc* pStreamAcc = nullptr; | 1225 CPDF_StreamAcc* pStreamAcc = nullptr; |
| 1217 if (m_ObjectStreamMap.Lookup((void*)(uintptr_t)objnum, (void*&)pStreamAcc)) | 1226 if (m_ObjectStreamMap.Lookup((void*)(uintptr_t)objnum, (void*&)pStreamAcc)) |
| 1218 return pStreamAcc; | 1227 return pStreamAcc; |
| 1219 | 1228 |
| 1220 const CPDF_Stream* pStream = | 1229 const CPDF_Stream* pStream = |
| 1221 ToStream(m_pDocument ? m_pDocument->GetIndirectObject(objnum) : nullptr); | 1230 ToStream(m_pDocument ? m_pDocument->GetIndirectObject(objnum) : nullptr); |
| 1222 if (!pStream) | 1231 if (!pStream) |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1652 } | 1661 } |
| 1653 m_LastXRefOffset += dwCount; | 1662 m_LastXRefOffset += dwCount; |
| 1654 FX_POSITION pos = m_ObjectStreamMap.GetStartPosition(); | 1663 FX_POSITION pos = m_ObjectStreamMap.GetStartPosition(); |
| 1655 while (pos) { | 1664 while (pos) { |
| 1656 void* objnum; | 1665 void* objnum; |
| 1657 CPDF_StreamAcc* pStream; | 1666 CPDF_StreamAcc* pStream; |
| 1658 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream); | 1667 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream); |
| 1659 delete pStream; | 1668 delete pStream; |
| 1660 } | 1669 } |
| 1661 m_ObjectStreamMap.RemoveAll(); | 1670 m_ObjectStreamMap.RemoveAll(); |
| 1671 m_ObjCache.clear(); |
| 1672 |
| 1662 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && | 1673 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && |
| 1663 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { | 1674 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { |
| 1664 m_LastXRefOffset = 0; | 1675 m_LastXRefOffset = 0; |
| 1665 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum; | 1676 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum; |
| 1666 return PDFPARSE_ERROR_FORMAT; | 1677 return PDFPARSE_ERROR_FORMAT; |
| 1667 } | 1678 } |
| 1668 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 1679 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
| 1669 sizeof(FX_FILESIZE), CompareFileSize); | 1680 sizeof(FX_FILESIZE), CompareFileSize); |
| 1670 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum; | 1681 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum; |
| 1671 return PDFPARSE_ERROR_SUCCESS; | 1682 return PDFPARSE_ERROR_SUCCESS; |
| (...skipping 3259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4931 if (!m_pLinearizedDict) | 4942 if (!m_pLinearizedDict) |
| 4932 return -1; | 4943 return -1; |
| 4933 CPDF_Array* pRange = m_pLinearizedDict->GetArray(FX_BSTRC("H")); | 4944 CPDF_Array* pRange = m_pLinearizedDict->GetArray(FX_BSTRC("H")); |
| 4934 if (!pRange) | 4945 if (!pRange) |
| 4935 return -1; | 4946 return -1; |
| 4936 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4947 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
| 4937 if (!pStreamLen) | 4948 if (!pStreamLen) |
| 4938 return -1; | 4949 return -1; |
| 4939 return pStreamLen->GetInteger(); | 4950 return pStreamLen->GetInteger(); |
| 4940 } | 4951 } |
| OLD | NEW |