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 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 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 FX_FILESIZE saved_pos = syntax.SavePos(); |
1208 syntax.RestorePos(offset + thisoff); | 1210 for (int32_t i = GetStreamNCount(pObjStream); i > 0; --i) { |
1209 return syntax.GetObject(pObjList, 0, 0, pContext); | 1211 FX_DWORD thisnum = syntax.GetDirectNum(); |
1212 FX_DWORD thisoff = syntax.GetDirectNum(); | |
1213 m_ObjCache[pObjStream][thisnum] = thisoff; | |
1210 } | 1214 } |
1215 syntax.RestorePos(saved_pos); | |
jun_fang
2015/11/19 16:19:45
nit: It seems that there is no need to restore the
Lei Zhang
2015/11/20 07:11:42
Done. I needed it in an earlier iteration, but the
| |
1211 } | 1216 } |
1212 return nullptr; | 1217 |
1218 const auto it = m_ObjCache[pObjStream].find(objnum); | |
1219 if (it == m_ObjCache[pObjStream].end()) | |
1220 return nullptr; | |
1221 | |
1222 syntax.RestorePos(offset + it->second); | |
1223 return syntax.GetObject(pObjList, 0, 0, pContext); | |
1213 } | 1224 } |
1214 | 1225 |
1215 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) { | 1226 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) { |
1216 CPDF_StreamAcc* pStreamAcc = nullptr; | 1227 CPDF_StreamAcc* pStreamAcc = nullptr; |
1217 if (m_ObjectStreamMap.Lookup((void*)(uintptr_t)objnum, (void*&)pStreamAcc)) | 1228 if (m_ObjectStreamMap.Lookup((void*)(uintptr_t)objnum, (void*&)pStreamAcc)) |
1218 return pStreamAcc; | 1229 return pStreamAcc; |
1219 | 1230 |
1220 const CPDF_Stream* pStream = | 1231 const CPDF_Stream* pStream = |
1221 ToStream(m_pDocument ? m_pDocument->GetIndirectObject(objnum) : nullptr); | 1232 ToStream(m_pDocument ? m_pDocument->GetIndirectObject(objnum) : nullptr); |
1222 if (!pStream) | 1233 if (!pStream) |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1652 } | 1663 } |
1653 m_LastXRefOffset += dwCount; | 1664 m_LastXRefOffset += dwCount; |
1654 FX_POSITION pos = m_ObjectStreamMap.GetStartPosition(); | 1665 FX_POSITION pos = m_ObjectStreamMap.GetStartPosition(); |
1655 while (pos) { | 1666 while (pos) { |
1656 void* objnum; | 1667 void* objnum; |
1657 CPDF_StreamAcc* pStream; | 1668 CPDF_StreamAcc* pStream; |
1658 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream); | 1669 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream); |
1659 delete pStream; | 1670 delete pStream; |
1660 } | 1671 } |
1661 m_ObjectStreamMap.RemoveAll(); | 1672 m_ObjectStreamMap.RemoveAll(); |
1673 m_ObjCache.clear(); | |
1674 | |
1662 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && | 1675 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && |
1663 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { | 1676 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { |
1664 m_LastXRefOffset = 0; | 1677 m_LastXRefOffset = 0; |
1665 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum; | 1678 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum; |
1666 return PDFPARSE_ERROR_FORMAT; | 1679 return PDFPARSE_ERROR_FORMAT; |
1667 } | 1680 } |
1668 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 1681 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
1669 sizeof(FX_FILESIZE), CompareFileSize); | 1682 sizeof(FX_FILESIZE), CompareFileSize); |
1670 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum; | 1683 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum; |
1671 return PDFPARSE_ERROR_SUCCESS; | 1684 return PDFPARSE_ERROR_SUCCESS; |
(...skipping 3264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4936 if (!m_pLinearizedDict) | 4949 if (!m_pLinearizedDict) |
4937 return -1; | 4950 return -1; |
4938 CPDF_Array* pRange = m_pLinearizedDict->GetArray(FX_BSTRC("H")); | 4951 CPDF_Array* pRange = m_pLinearizedDict->GetArray(FX_BSTRC("H")); |
4939 if (!pRange) | 4952 if (!pRange) |
4940 return -1; | 4953 return -1; |
4941 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4954 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
4942 if (!pStreamLen) | 4955 if (!pStreamLen) |
4943 return -1; | 4956 return -1; |
4944 return pStreamLen->GetInteger(); | 4957 return pStreamLen->GetInteger(); |
4945 } | 4958 } |
OLD | NEW |