| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 return it != m_ObjectInfo.end() ? it->second.pos : 0; | 124 return it != m_ObjectInfo.end() ? it->second.pos : 0; |
| 125 } | 125 } |
| 126 | 126 |
| 127 uint8_t CPDF_Parser::GetObjectType(FX_DWORD objnum) const { | 127 uint8_t CPDF_Parser::GetObjectType(FX_DWORD objnum) const { |
| 128 ASSERT(IsValidObjectNumber(objnum)); | 128 ASSERT(IsValidObjectNumber(objnum)); |
| 129 auto it = m_ObjectInfo.find(objnum); | 129 auto it = m_ObjectInfo.find(objnum); |
| 130 return it != m_ObjectInfo.end() ? it->second.type : 0; | 130 return it != m_ObjectInfo.end() ? it->second.type : 0; |
| 131 } | 131 } |
| 132 | 132 |
| 133 uint16_t CPDF_Parser::GetObjectGenNum(FX_DWORD objnum) const { | 133 uint16_t CPDF_Parser::GetObjectGenNum(FX_DWORD objnum) const { |
| 134 return m_ObjVersion[objnum]; | 134 ASSERT(IsValidObjectNumber(objnum)); |
| 135 auto it = m_ObjectInfo.find(objnum); |
| 136 return it != m_ObjectInfo.end() ? it->second.gennum : 0; |
| 135 } | 137 } |
| 136 | 138 |
| 137 bool CPDF_Parser::IsObjectFreeOrNull(FX_DWORD objnum) const { | 139 bool CPDF_Parser::IsObjectFreeOrNull(FX_DWORD objnum) const { |
| 138 uint8_t type = GetObjectType(objnum); | 140 uint8_t type = GetObjectType(objnum); |
| 139 return type == 0 || type == 255; | 141 return type == 0 || type == 255; |
| 140 } | 142 } |
| 141 | 143 |
| 142 void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) { | 144 void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) { |
| 143 m_pEncryptDict = pDict; | 145 m_pEncryptDict = pDict; |
| 144 } | 146 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 172 SetEncryptDictionary(nullptr); | 174 SetEncryptDictionary(nullptr); |
| 173 if (m_bOwnFileRead && m_Syntax.m_pFileAccess) { | 175 if (m_bOwnFileRead && m_Syntax.m_pFileAccess) { |
| 174 m_Syntax.m_pFileAccess->Release(); | 176 m_Syntax.m_pFileAccess->Release(); |
| 175 m_Syntax.m_pFileAccess = nullptr; | 177 m_Syntax.m_pFileAccess = nullptr; |
| 176 } | 178 } |
| 177 m_ObjectStreamMap.clear(); | 179 m_ObjectStreamMap.clear(); |
| 178 m_ObjCache.clear(); | 180 m_ObjCache.clear(); |
| 179 | 181 |
| 180 m_SortedOffset.RemoveAll(); | 182 m_SortedOffset.RemoveAll(); |
| 181 m_ObjectInfo.clear(); | 183 m_ObjectInfo.clear(); |
| 182 m_ObjVersion.RemoveAll(); | |
| 183 int32_t iLen = m_Trailers.GetSize(); | 184 int32_t iLen = m_Trailers.GetSize(); |
| 184 for (int32_t i = 0; i < iLen; ++i) { | 185 for (int32_t i = 0; i < iLen; ++i) { |
| 185 if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i)) | 186 if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i)) |
| 186 trailer->Release(); | 187 trailer->Release(); |
| 187 } | 188 } |
| 188 m_Trailers.RemoveAll(); | 189 m_Trailers.RemoveAll(); |
| 189 if (m_pLinearized) { | 190 if (m_pLinearized) { |
| 190 m_pLinearized->Release(); | 191 m_pLinearized->Release(); |
| 191 m_pLinearized = nullptr; | 192 m_pLinearized = nullptr; |
| 192 } | 193 } |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 for (int32_t c = 0; c < 10; c++) { | 480 for (int32_t c = 0; c < 10; c++) { |
| 480 if (!std::isdigit(pEntry[c])) | 481 if (!std::isdigit(pEntry[c])) |
| 481 return FALSE; | 482 return FALSE; |
| 482 } | 483 } |
| 483 } | 484 } |
| 484 m_ObjectInfo[objnum].pos = offset; | 485 m_ObjectInfo[objnum].pos = offset; |
| 485 int32_t version = FXSYS_atoi(pEntry + 11); | 486 int32_t version = FXSYS_atoi(pEntry + 11); |
| 486 if (version >= 1) { | 487 if (version >= 1) { |
| 487 m_bVersionUpdated = TRUE; | 488 m_bVersionUpdated = TRUE; |
| 488 } | 489 } |
| 489 m_ObjVersion.SetAtGrow(objnum, version); | 490 m_ObjectInfo[objnum].gennum = version; |
| 490 if (m_ObjectInfo[objnum].pos < m_Syntax.m_FileLen) { | 491 if (m_ObjectInfo[objnum].pos < m_Syntax.m_FileLen) { |
| 491 void* pResult = FXSYS_bsearch( | 492 void* pResult = FXSYS_bsearch( |
| 492 &m_ObjectInfo[objnum].pos, m_SortedOffset.GetData(), | 493 &m_ObjectInfo[objnum].pos, m_SortedOffset.GetData(), |
| 493 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), CompareFileSize); | 494 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), CompareFileSize); |
| 494 if (!pResult) { | 495 if (!pResult) { |
| 495 m_SortedOffset.Add(m_ObjectInfo[objnum].pos); | 496 m_SortedOffset.Add(m_ObjectInfo[objnum].pos); |
| 496 } | 497 } |
| 497 } | 498 } |
| 498 m_ObjectInfo[objnum].type = 1; | 499 m_ObjectInfo[objnum].type = 1; |
| 499 } | 500 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 for (int32_t c = 0; c < 10; c++) { | 562 for (int32_t c = 0; c < 10; c++) { |
| 562 if (!std::isdigit(pEntry[c])) | 563 if (!std::isdigit(pEntry[c])) |
| 563 return false; | 564 return false; |
| 564 } | 565 } |
| 565 } | 566 } |
| 566 m_ObjectInfo[objnum].pos = offset; | 567 m_ObjectInfo[objnum].pos = offset; |
| 567 int32_t version = FXSYS_atoi(pEntry + 11); | 568 int32_t version = FXSYS_atoi(pEntry + 11); |
| 568 if (version >= 1) { | 569 if (version >= 1) { |
| 569 m_bVersionUpdated = TRUE; | 570 m_bVersionUpdated = TRUE; |
| 570 } | 571 } |
| 571 m_ObjVersion.SetAtGrow(objnum, version); | 572 m_ObjectInfo[objnum].gennum = version; |
| 572 if (m_ObjectInfo[objnum].pos < m_Syntax.m_FileLen && | 573 if (m_ObjectInfo[objnum].pos < m_Syntax.m_FileLen && |
| 573 !FindPosInOffsets(m_ObjectInfo[objnum].pos)) { | 574 !FindPosInOffsets(m_ObjectInfo[objnum].pos)) { |
| 574 m_SortedOffset.Add(m_ObjectInfo[objnum].pos); | 575 m_SortedOffset.Add(m_ObjectInfo[objnum].pos); |
| 575 } | 576 } |
| 576 m_ObjectInfo[objnum].type = 1; | 577 m_ObjectInfo[objnum].type = 1; |
| 577 } | 578 } |
| 578 } | 579 } |
| 579 } | 580 } |
| 580 } | 581 } |
| 581 m_Syntax.RestorePos(SavedPos + count * recordsize); | 582 m_Syntax.RestorePos(SavedPos + count * recordsize); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 599 } | 600 } |
| 600 } | 601 } |
| 601 m_ObjectStreamMap.clear(); | 602 m_ObjectStreamMap.clear(); |
| 602 m_bXRefStream = TRUE; | 603 m_bXRefStream = TRUE; |
| 603 return TRUE; | 604 return TRUE; |
| 604 } | 605 } |
| 605 | 606 |
| 606 FX_BOOL CPDF_Parser::RebuildCrossRef() { | 607 FX_BOOL CPDF_Parser::RebuildCrossRef() { |
| 607 m_ObjectInfo.clear(); | 608 m_ObjectInfo.clear(); |
| 608 m_SortedOffset.RemoveAll(); | 609 m_SortedOffset.RemoveAll(); |
| 609 m_ObjVersion.RemoveAll(); | |
| 610 if (m_pTrailer) { | 610 if (m_pTrailer) { |
| 611 m_pTrailer->Release(); | 611 m_pTrailer->Release(); |
| 612 m_pTrailer = NULL; | 612 m_pTrailer = NULL; |
| 613 } | 613 } |
| 614 int32_t status = 0; | 614 int32_t status = 0; |
| 615 int32_t inside_index = 0; | 615 int32_t inside_index = 0; |
| 616 FX_DWORD objnum = 0; | 616 FX_DWORD objnum = 0; |
| 617 FX_DWORD gennum = 0; | 617 FX_DWORD gennum = 0; |
| 618 int32_t depth = 0; | 618 int32_t depth = 0; |
| 619 const FX_DWORD kBufferSize = 4096; | 619 const FX_DWORD kBufferSize = 4096; |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 FX_FILESIZE nLen = obj_end - obj_pos - offset; | 804 FX_FILESIZE nLen = obj_end - obj_pos - offset; |
| 805 if ((FX_DWORD)nLen > size - i) { | 805 if ((FX_DWORD)nLen > size - i) { |
| 806 pos = obj_end + m_Syntax.m_HeaderOffset; | 806 pos = obj_end + m_Syntax.m_HeaderOffset; |
| 807 bOverFlow = true; | 807 bOverFlow = true; |
| 808 } else { | 808 } else { |
| 809 i += (FX_DWORD)nLen; | 809 i += (FX_DWORD)nLen; |
| 810 } | 810 } |
| 811 if (!m_ObjectInfo.empty() && IsValidObjectNumber(objnum) && | 811 if (!m_ObjectInfo.empty() && IsValidObjectNumber(objnum) && |
| 812 m_ObjectInfo[objnum].pos) { | 812 m_ObjectInfo[objnum].pos) { |
| 813 if (pObject) { | 813 if (pObject) { |
| 814 FX_DWORD oldgen = m_ObjVersion.GetAt(objnum); | 814 FX_DWORD oldgen = GetObjectGenNum(objnum); |
| 815 m_ObjectInfo[objnum].pos = obj_pos; | 815 m_ObjectInfo[objnum].pos = obj_pos; |
| 816 m_ObjVersion.SetAt(objnum, (int16_t)gennum); | 816 m_ObjectInfo[objnum].gennum = gennum; |
| 817 if (oldgen != gennum) { | 817 if (oldgen != gennum) { |
| 818 m_bVersionUpdated = TRUE; | 818 m_bVersionUpdated = TRUE; |
| 819 } | 819 } |
| 820 } | 820 } |
| 821 } else { | 821 } else { |
| 822 m_ObjectInfo[objnum].pos = obj_pos; | 822 m_ObjectInfo[objnum].pos = obj_pos; |
| 823 m_ObjectInfo[objnum].type = 1; | 823 m_ObjectInfo[objnum].type = 1; |
| 824 m_ObjVersion.SetAtGrow(objnum, (int16_t)gennum); | 824 m_ObjectInfo[objnum].gennum = gennum; |
| 825 } | 825 } |
| 826 if (pObject) { | 826 if (pObject) { |
| 827 pObject->Release(); | 827 pObject->Release(); |
| 828 } | 828 } |
| 829 } | 829 } |
| 830 --i; | 830 --i; |
| 831 status = 0; | 831 status = 0; |
| 832 break; | 832 break; |
| 833 } | 833 } |
| 834 break; | 834 break; |
| (...skipping 4017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4852 if (!m_pLinearizedDict) | 4852 if (!m_pLinearizedDict) |
| 4853 return -1; | 4853 return -1; |
| 4854 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); | 4854 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); |
| 4855 if (!pRange) | 4855 if (!pRange) |
| 4856 return -1; | 4856 return -1; |
| 4857 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4857 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
| 4858 if (!pStreamLen) | 4858 if (!pStreamLen) |
| 4859 return -1; | 4859 return -1; |
| 4860 return pStreamLen->GetInteger(); | 4860 return pStreamLen->GetInteger(); |
| 4861 } | 4861 } |
| OLD | NEW |