OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/fpdfapi/parser/cpdf_parser.h" | 7 #include "core/fpdfapi/parser/cpdf_parser.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 | 113 |
114 void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) { | 114 void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) { |
115 m_pEncryptDict = pDict; | 115 m_pEncryptDict = pDict; |
116 } | 116 } |
117 | 117 |
118 CPDF_CryptoHandler* CPDF_Parser::GetCryptoHandler() { | 118 CPDF_CryptoHandler* CPDF_Parser::GetCryptoHandler() { |
119 return m_pSyntax->m_pCryptoHandler.get(); | 119 return m_pSyntax->m_pCryptoHandler.get(); |
120 } | 120 } |
121 | 121 |
122 IFX_FileRead* CPDF_Parser::GetFileAccess() const { | 122 IFX_SeekableReadStream* CPDF_Parser::GetFileAccess() const { |
123 return m_pSyntax->m_pFileAccess; | 123 return m_pSyntax->m_pFileAccess; |
124 } | 124 } |
125 | 125 |
126 void CPDF_Parser::ShrinkObjectMap(uint32_t objnum) { | 126 void CPDF_Parser::ShrinkObjectMap(uint32_t objnum) { |
127 if (objnum == 0) { | 127 if (objnum == 0) { |
128 m_ObjectInfo.clear(); | 128 m_ObjectInfo.clear(); |
129 return; | 129 return; |
130 } | 130 } |
131 | 131 |
132 auto it = m_ObjectInfo.lower_bound(objnum); | 132 auto it = m_ObjectInfo.lower_bound(objnum); |
133 while (it != m_ObjectInfo.end()) { | 133 while (it != m_ObjectInfo.end()) { |
134 auto saved_it = it++; | 134 auto saved_it = it++; |
135 m_ObjectInfo.erase(saved_it); | 135 m_ObjectInfo.erase(saved_it); |
136 } | 136 } |
137 | 137 |
138 if (!pdfium::ContainsKey(m_ObjectInfo, objnum - 1)) | 138 if (!pdfium::ContainsKey(m_ObjectInfo, objnum - 1)) |
139 m_ObjectInfo[objnum - 1].pos = 0; | 139 m_ObjectInfo[objnum - 1].pos = 0; |
140 } | 140 } |
141 | 141 |
142 CPDF_Parser::Error CPDF_Parser::StartParse(IFX_FileRead* pFileAccess, | 142 CPDF_Parser::Error CPDF_Parser::StartParse(IFX_SeekableReadStream* pFileAccess, |
143 CPDF_Document* pDocument) { | 143 CPDF_Document* pDocument) { |
144 ASSERT(!m_bHasParsed); | 144 ASSERT(!m_bHasParsed); |
145 m_bHasParsed = true; | 145 m_bHasParsed = true; |
146 | 146 |
147 m_bXRefStream = FALSE; | 147 m_bXRefStream = FALSE; |
148 m_LastXRefOffset = 0; | 148 m_LastXRefOffset = 0; |
149 m_bOwnFileRead = true; | 149 m_bOwnFileRead = true; |
150 | 150 |
151 int32_t offset = GetHeaderOffset(pFileAccess); | 151 int32_t offset = GetHeaderOffset(pFileAccess); |
152 if (offset == -1) { | 152 if (offset == -1) { |
(...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 | 1431 |
1432 uint32_t dwPermission = m_pSecurityHandler->GetPermissions(); | 1432 uint32_t dwPermission = m_pSecurityHandler->GetPermissions(); |
1433 if (m_pEncryptDict && m_pEncryptDict->GetStringFor("Filter") == "Standard") { | 1433 if (m_pEncryptDict && m_pEncryptDict->GetStringFor("Filter") == "Standard") { |
1434 // See PDF Reference 1.7, page 123, table 3.20. | 1434 // See PDF Reference 1.7, page 123, table 3.20. |
1435 dwPermission &= 0xFFFFFFFC; | 1435 dwPermission &= 0xFFFFFFFC; |
1436 dwPermission |= 0xFFFFF0C0; | 1436 dwPermission |= 0xFFFFF0C0; |
1437 } | 1437 } |
1438 return dwPermission; | 1438 return dwPermission; |
1439 } | 1439 } |
1440 | 1440 |
1441 FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, | 1441 FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_SeekableReadStream* pFileAccess, |
1442 uint32_t offset) { | 1442 uint32_t offset) { |
1443 m_pSyntax->InitParser(pFileAccess, offset); | 1443 m_pSyntax->InitParser(pFileAccess, offset); |
1444 m_pSyntax->RestorePos(m_pSyntax->m_HeaderOffset + 9); | 1444 m_pSyntax->RestorePos(m_pSyntax->m_HeaderOffset + 9); |
1445 | 1445 |
1446 FX_FILESIZE SavedPos = m_pSyntax->SavePos(); | 1446 FX_FILESIZE SavedPos = m_pSyntax->SavePos(); |
1447 bool bIsNumber; | 1447 bool bIsNumber; |
1448 CFX_ByteString word = m_pSyntax->GetNextWord(&bIsNumber); | 1448 CFX_ByteString word = m_pSyntax->GetNextWord(&bIsNumber); |
1449 if (!bIsNumber) | 1449 if (!bIsNumber) |
1450 return FALSE; | 1450 return FALSE; |
1451 | 1451 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1484 if (CPDF_Number* pTable = ToNumber(pDict->GetObjectFor("T"))) | 1484 if (CPDF_Number* pTable = ToNumber(pDict->GetObjectFor("T"))) |
1485 m_LastXRefOffset = pTable->GetInteger(); | 1485 m_LastXRefOffset = pTable->GetInteger(); |
1486 | 1486 |
1487 return TRUE; | 1487 return TRUE; |
1488 } | 1488 } |
1489 m_pLinearized->Release(); | 1489 m_pLinearized->Release(); |
1490 m_pLinearized = nullptr; | 1490 m_pLinearized = nullptr; |
1491 return FALSE; | 1491 return FALSE; |
1492 } | 1492 } |
1493 | 1493 |
1494 CPDF_Parser::Error CPDF_Parser::StartLinearizedParse(IFX_FileRead* pFileAccess, | 1494 CPDF_Parser::Error CPDF_Parser::StartLinearizedParse( |
1495 CPDF_Document* pDocument) { | 1495 IFX_SeekableReadStream* pFileAccess, |
| 1496 CPDF_Document* pDocument) { |
1496 ASSERT(!m_bHasParsed); | 1497 ASSERT(!m_bHasParsed); |
1497 | 1498 |
1498 m_bXRefStream = FALSE; | 1499 m_bXRefStream = FALSE; |
1499 m_LastXRefOffset = 0; | 1500 m_LastXRefOffset = 0; |
1500 m_bOwnFileRead = true; | 1501 m_bOwnFileRead = true; |
1501 | 1502 |
1502 int32_t offset = GetHeaderOffset(pFileAccess); | 1503 int32_t offset = GetHeaderOffset(pFileAccess); |
1503 if (offset == -1) | 1504 if (offset == -1) |
1504 return FORMAT_ERROR; | 1505 return FORMAT_ERROR; |
1505 | 1506 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1618 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && | 1619 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && |
1619 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { | 1620 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { |
1620 m_LastXRefOffset = 0; | 1621 m_LastXRefOffset = 0; |
1621 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1622 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
1622 return FORMAT_ERROR; | 1623 return FORMAT_ERROR; |
1623 } | 1624 } |
1624 | 1625 |
1625 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; | 1626 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; |
1626 return SUCCESS; | 1627 return SUCCESS; |
1627 } | 1628 } |
OLD | NEW |