| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 if (m_pTrailer) { | 154 if (m_pTrailer) { |
| 155 m_pTrailer->Release(); | 155 m_pTrailer->Release(); |
| 156 m_pTrailer = NULL; | 156 m_pTrailer = NULL; |
| 157 } | 157 } |
| 158 ReleaseEncryptHandler(); | 158 ReleaseEncryptHandler(); |
| 159 SetEncryptDictionary(NULL); | 159 SetEncryptDictionary(NULL); |
| 160 if (m_bOwnFileRead && m_Syntax.m_pFileAccess) { | 160 if (m_bOwnFileRead && m_Syntax.m_pFileAccess) { |
| 161 m_Syntax.m_pFileAccess->Release(); | 161 m_Syntax.m_pFileAccess->Release(); |
| 162 m_Syntax.m_pFileAccess = NULL; | 162 m_Syntax.m_pFileAccess = NULL; |
| 163 } | 163 } |
| 164 FX_POSITION pos = m_ObjectStreamMap.GetStartPosition(); | 164 m_ObjectStreamMap.clear(); |
| 165 while (pos) { | |
| 166 void* objnum; | |
| 167 CPDF_StreamAcc* pStream; | |
| 168 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream); | |
| 169 delete pStream; | |
| 170 } | |
| 171 m_ObjectStreamMap.RemoveAll(); | |
| 172 m_ObjCache.clear(); | 165 m_ObjCache.clear(); |
| 173 | 166 |
| 174 m_SortedOffset.RemoveAll(); | 167 m_SortedOffset.RemoveAll(); |
| 175 m_ObjectInfo.clear(); | 168 m_ObjectInfo.clear(); |
| 176 m_V5Type.RemoveAll(); | 169 m_V5Type.RemoveAll(); |
| 177 m_ObjVersion.RemoveAll(); | 170 m_ObjVersion.RemoveAll(); |
| 178 int32_t iLen = m_Trailers.GetSize(); | 171 int32_t iLen = m_Trailers.GetSize(); |
| 179 for (int32_t i = 0; i < iLen; ++i) { | 172 for (int32_t i = 0; i < iLen; ++i) { |
| 180 if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i)) | 173 if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i)) |
| 181 trailer->Release(); | 174 trailer->Release(); |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 while (xrefpos) { | 602 while (xrefpos) { |
| 610 seen_xrefpos.insert(xrefpos); | 603 seen_xrefpos.insert(xrefpos); |
| 611 if (!LoadCrossRefV5(&xrefpos, FALSE)) { | 604 if (!LoadCrossRefV5(&xrefpos, FALSE)) { |
| 612 return FALSE; | 605 return FALSE; |
| 613 } | 606 } |
| 614 // Check for circular references. | 607 // Check for circular references. |
| 615 if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) { | 608 if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) { |
| 616 return FALSE; | 609 return FALSE; |
| 617 } | 610 } |
| 618 } | 611 } |
| 619 m_ObjectStreamMap.InitHashTable(101, FALSE); | 612 m_ObjectStreamMap.clear(); |
| 620 m_bXRefStream = TRUE; | 613 m_bXRefStream = TRUE; |
| 621 return TRUE; | 614 return TRUE; |
| 622 } | 615 } |
| 623 | 616 |
| 624 FX_BOOL CPDF_Parser::RebuildCrossRef() { | 617 FX_BOOL CPDF_Parser::RebuildCrossRef() { |
| 625 m_ObjectInfo.clear(); | 618 m_ObjectInfo.clear(); |
| 626 m_V5Type.RemoveAll(); | 619 m_V5Type.RemoveAll(); |
| 627 m_SortedOffset.RemoveAll(); | 620 m_SortedOffset.RemoveAll(); |
| 628 m_ObjVersion.RemoveAll(); | 621 m_ObjVersion.RemoveAll(); |
| 629 if (m_pTrailer) { | 622 if (m_pTrailer) { |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 | 1238 |
| 1246 const auto it = m_ObjCache[pObjStream].find(objnum); | 1239 const auto it = m_ObjCache[pObjStream].find(objnum); |
| 1247 if (it == m_ObjCache[pObjStream].end()) | 1240 if (it == m_ObjCache[pObjStream].end()) |
| 1248 return nullptr; | 1241 return nullptr; |
| 1249 | 1242 |
| 1250 syntax.RestorePos(offset + it->second); | 1243 syntax.RestorePos(offset + it->second); |
| 1251 return syntax.GetObject(pObjList, 0, 0, pContext, true); | 1244 return syntax.GetObject(pObjList, 0, 0, pContext, true); |
| 1252 } | 1245 } |
| 1253 | 1246 |
| 1254 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) { | 1247 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) { |
| 1255 CPDF_StreamAcc* pStreamAcc = nullptr; | 1248 auto it = m_ObjectStreamMap.find(objnum); |
| 1256 if (m_ObjectStreamMap.Lookup((void*)(uintptr_t)objnum, (void*&)pStreamAcc)) | 1249 if (it != m_ObjectStreamMap.end()) |
| 1257 return pStreamAcc; | 1250 return it->second.get(); |
| 1258 | 1251 |
| 1259 const CPDF_Stream* pStream = ToStream( | 1252 const CPDF_Stream* pStream = ToStream( |
| 1260 m_pDocument ? m_pDocument->GetIndirectObject(objnum, nullptr) : nullptr); | 1253 m_pDocument ? m_pDocument->GetIndirectObject(objnum, nullptr) : nullptr); |
| 1261 if (!pStream) | 1254 if (!pStream) |
| 1262 return nullptr; | 1255 return nullptr; |
| 1263 | 1256 |
| 1264 pStreamAcc = new CPDF_StreamAcc; | 1257 CPDF_StreamAcc* pStreamAcc = new CPDF_StreamAcc; |
| 1265 pStreamAcc->LoadAllData(pStream); | 1258 pStreamAcc->LoadAllData(pStream); |
| 1266 m_ObjectStreamMap.SetAt((void*)(uintptr_t)objnum, pStreamAcc); | 1259 m_ObjectStreamMap[objnum].reset(pStreamAcc); |
| 1267 return pStreamAcc; | 1260 return pStreamAcc; |
| 1268 } | 1261 } |
| 1269 | 1262 |
| 1270 FX_FILESIZE CPDF_Parser::GetObjectSize(FX_DWORD objnum) const { | 1263 FX_FILESIZE CPDF_Parser::GetObjectSize(FX_DWORD objnum) const { |
| 1271 if (!IsValidObjectNumber(objnum)) | 1264 if (!IsValidObjectNumber(objnum)) |
| 1272 return 0; | 1265 return 0; |
| 1273 | 1266 |
| 1274 if (m_V5Type[objnum] == 2) | 1267 if (m_V5Type[objnum] == 2) |
| 1275 objnum = GetObjectPositionOrZero(objnum); | 1268 objnum = GetObjectPositionOrZero(objnum); |
| 1276 | 1269 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1664 while (xrefpos) { | 1657 while (xrefpos) { |
| 1665 seen_xrefpos.insert(xrefpos); | 1658 seen_xrefpos.insert(xrefpos); |
| 1666 if (!LoadCrossRefV5(&xrefpos, FALSE)) { | 1659 if (!LoadCrossRefV5(&xrefpos, FALSE)) { |
| 1667 return FALSE; | 1660 return FALSE; |
| 1668 } | 1661 } |
| 1669 // Check for circular references. | 1662 // Check for circular references. |
| 1670 if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) { | 1663 if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) { |
| 1671 return FALSE; | 1664 return FALSE; |
| 1672 } | 1665 } |
| 1673 } | 1666 } |
| 1674 m_ObjectStreamMap.InitHashTable(101, FALSE); | 1667 m_ObjectStreamMap.clear(); |
| 1675 m_bXRefStream = TRUE; | 1668 m_bXRefStream = TRUE; |
| 1676 return TRUE; | 1669 return TRUE; |
| 1677 } | 1670 } |
| 1678 FX_DWORD CPDF_Parser::LoadLinearizedMainXRefTable() { | 1671 FX_DWORD CPDF_Parser::LoadLinearizedMainXRefTable() { |
| 1679 FX_DWORD dwSaveMetadataObjnum = m_Syntax.m_MetadataObjnum; | 1672 FX_DWORD dwSaveMetadataObjnum = m_Syntax.m_MetadataObjnum; |
| 1680 m_Syntax.m_MetadataObjnum = 0; | 1673 m_Syntax.m_MetadataObjnum = 0; |
| 1681 if (m_pTrailer) { | 1674 if (m_pTrailer) { |
| 1682 m_pTrailer->Release(); | 1675 m_pTrailer->Release(); |
| 1683 m_pTrailer = NULL; | 1676 m_pTrailer = NULL; |
| 1684 } | 1677 } |
| 1685 m_Syntax.RestorePos(m_LastXRefOffset - m_Syntax.m_HeaderOffset); | 1678 m_Syntax.RestorePos(m_LastXRefOffset - m_Syntax.m_HeaderOffset); |
| 1686 uint8_t ch = 0; | 1679 uint8_t ch = 0; |
| 1687 FX_DWORD dwCount = 0; | 1680 FX_DWORD dwCount = 0; |
| 1688 m_Syntax.GetNextChar(ch); | 1681 m_Syntax.GetNextChar(ch); |
| 1689 while (PDFCharIsWhitespace(ch)) { | 1682 while (PDFCharIsWhitespace(ch)) { |
| 1690 ++dwCount; | 1683 ++dwCount; |
| 1691 if (m_Syntax.m_FileLen >= | 1684 if (m_Syntax.m_FileLen >= |
| 1692 (FX_FILESIZE)(m_Syntax.SavePos() + m_Syntax.m_HeaderOffset)) { | 1685 (FX_FILESIZE)(m_Syntax.SavePos() + m_Syntax.m_HeaderOffset)) { |
| 1693 break; | 1686 break; |
| 1694 } | 1687 } |
| 1695 m_Syntax.GetNextChar(ch); | 1688 m_Syntax.GetNextChar(ch); |
| 1696 } | 1689 } |
| 1697 m_LastXRefOffset += dwCount; | 1690 m_LastXRefOffset += dwCount; |
| 1698 FX_POSITION pos = m_ObjectStreamMap.GetStartPosition(); | 1691 m_ObjectStreamMap.clear(); |
| 1699 while (pos) { | |
| 1700 void* objnum; | |
| 1701 CPDF_StreamAcc* pStream; | |
| 1702 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream); | |
| 1703 delete pStream; | |
| 1704 } | |
| 1705 m_ObjectStreamMap.RemoveAll(); | |
| 1706 m_ObjCache.clear(); | 1692 m_ObjCache.clear(); |
| 1707 | 1693 |
| 1708 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && | 1694 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && |
| 1709 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { | 1695 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { |
| 1710 m_LastXRefOffset = 0; | 1696 m_LastXRefOffset = 0; |
| 1711 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum; | 1697 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum; |
| 1712 return PDFPARSE_ERROR_FORMAT; | 1698 return PDFPARSE_ERROR_FORMAT; |
| 1713 } | 1699 } |
| 1714 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 1700 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
| 1715 sizeof(FX_FILESIZE), CompareFileSize); | 1701 sizeof(FX_FILESIZE), CompareFileSize); |
| (...skipping 3278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4994 if (!m_pLinearizedDict) | 4980 if (!m_pLinearizedDict) |
| 4995 return -1; | 4981 return -1; |
| 4996 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); | 4982 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); |
| 4997 if (!pRange) | 4983 if (!pRange) |
| 4998 return -1; | 4984 return -1; |
| 4999 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4985 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
| 5000 if (!pStreamLen) | 4986 if (!pStreamLen) |
| 5001 return -1; | 4987 return -1; |
| 5002 return pStreamLen->GetInteger(); | 4988 return pStreamLen->GetInteger(); |
| 5003 } | 4989 } |
| OLD | NEW |