Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1246)

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp

Issue 1634123004: War on #defines - part 2 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Missing break Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 for (int32_t i = 0; i < iLen; ++i) { 172 for (int32_t i = 0; i < iLen; ++i) {
173 if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i)) 173 if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i))
174 trailer->Release(); 174 trailer->Release();
175 } 175 }
176 m_Trailers.RemoveAll(); 176 m_Trailers.RemoveAll();
177 if (m_pLinearized) { 177 if (m_pLinearized) {
178 m_pLinearized->Release(); 178 m_pLinearized->Release();
179 m_pLinearized = NULL; 179 m_pLinearized = NULL;
180 } 180 }
181 } 181 }
182 CPDF_SecurityHandler* FPDF_CreateStandardSecurityHandler(); 182
183 CPDF_SecurityHandler* FPDF_CreatePubKeyHandler(void*); 183 CPDF_Parser::Error CPDF_Parser::StartParse(IFX_FileRead* pFileAccess,
184 FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess, 184 FX_BOOL bReParse,
185 FX_BOOL bReParse, 185 FX_BOOL bOwnFileRead) {
186 FX_BOOL bOwnFileRead) {
187 CloseParser(bReParse); 186 CloseParser(bReParse);
188 m_bXRefStream = FALSE; 187 m_bXRefStream = FALSE;
189 m_LastXRefOffset = 0; 188 m_LastXRefOffset = 0;
190 m_bOwnFileRead = bOwnFileRead; 189 m_bOwnFileRead = bOwnFileRead;
191 190
192 int32_t offset = GetHeaderOffset(pFileAccess); 191 int32_t offset = GetHeaderOffset(pFileAccess);
193 if (offset == -1) { 192 if (offset == -1) {
194 if (bOwnFileRead && pFileAccess) 193 if (bOwnFileRead && pFileAccess)
195 pFileAccess->Release(); 194 pFileAccess->Release();
196 return PDFPARSE_ERROR_FORMAT; 195 return FORMAT_ERROR;
197 } 196 }
198 m_Syntax.InitParser(pFileAccess, offset); 197 m_Syntax.InitParser(pFileAccess, offset);
199 198
200 uint8_t ch; 199 uint8_t ch;
201 if (!m_Syntax.GetCharAt(5, ch)) 200 if (!m_Syntax.GetCharAt(5, ch))
202 return PDFPARSE_ERROR_FORMAT; 201 return FORMAT_ERROR;
203 if (std::isdigit(ch)) 202 if (std::isdigit(ch))
204 m_FileVersion = FXSYS_toDecimalDigit(ch) * 10; 203 m_FileVersion = FXSYS_toDecimalDigit(ch) * 10;
205 204
206 if (!m_Syntax.GetCharAt(7, ch)) 205 if (!m_Syntax.GetCharAt(7, ch))
207 return PDFPARSE_ERROR_FORMAT; 206 return FORMAT_ERROR;
208 if (std::isdigit(ch)) 207 if (std::isdigit(ch))
209 m_FileVersion += FXSYS_toDecimalDigit(ch); 208 m_FileVersion += FXSYS_toDecimalDigit(ch);
210 209
211 if (m_Syntax.m_FileLen < m_Syntax.m_HeaderOffset + 9) 210 if (m_Syntax.m_FileLen < m_Syntax.m_HeaderOffset + 9)
212 return PDFPARSE_ERROR_FORMAT; 211 return FORMAT_ERROR;
213 212
214 m_Syntax.RestorePos(m_Syntax.m_FileLen - m_Syntax.m_HeaderOffset - 9); 213 m_Syntax.RestorePos(m_Syntax.m_FileLen - m_Syntax.m_HeaderOffset - 9);
215 if (!bReParse) 214 if (!bReParse)
216 m_pDocument = new CPDF_Document(this); 215 m_pDocument = new CPDF_Document(this);
217 216
218 FX_BOOL bXRefRebuilt = FALSE; 217 FX_BOOL bXRefRebuilt = FALSE;
219 if (m_Syntax.SearchWord("startxref", TRUE, FALSE, 4096)) { 218 if (m_Syntax.SearchWord("startxref", TRUE, FALSE, 4096)) {
220 FX_FILESIZE startxref_offset = m_Syntax.SavePos(); 219 FX_FILESIZE startxref_offset = m_Syntax.SavePos();
221 void* pResult = FXSYS_bsearch(&startxref_offset, m_SortedOffset.GetData(), 220 void* pResult = FXSYS_bsearch(&startxref_offset, m_SortedOffset.GetData(),
222 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), 221 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE),
223 CompareFileSize); 222 CompareFileSize);
224 if (!pResult) 223 if (!pResult)
225 m_SortedOffset.Add(startxref_offset); 224 m_SortedOffset.Add(startxref_offset);
226 225
227 m_Syntax.GetKeyword(); 226 m_Syntax.GetKeyword();
228 bool bNumber; 227 bool bNumber;
229 CFX_ByteString xrefpos_str = m_Syntax.GetNextWord(&bNumber); 228 CFX_ByteString xrefpos_str = m_Syntax.GetNextWord(&bNumber);
230 if (!bNumber) 229 if (!bNumber)
231 return PDFPARSE_ERROR_FORMAT; 230 return FORMAT_ERROR;
232 231
233 m_LastXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); 232 m_LastXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str);
234 if (!LoadAllCrossRefV4(m_LastXRefOffset) && 233 if (!LoadAllCrossRefV4(m_LastXRefOffset) &&
235 !LoadAllCrossRefV5(m_LastXRefOffset)) { 234 !LoadAllCrossRefV5(m_LastXRefOffset)) {
236 if (!RebuildCrossRef()) 235 if (!RebuildCrossRef())
237 return PDFPARSE_ERROR_FORMAT; 236 return FORMAT_ERROR;
238 237
239 bXRefRebuilt = TRUE; 238 bXRefRebuilt = TRUE;
240 m_LastXRefOffset = 0; 239 m_LastXRefOffset = 0;
241 } 240 }
242 } else { 241 } else {
243 if (!RebuildCrossRef()) 242 if (!RebuildCrossRef())
244 return PDFPARSE_ERROR_FORMAT; 243 return FORMAT_ERROR;
245 244
246 bXRefRebuilt = TRUE; 245 bXRefRebuilt = TRUE;
247 } 246 }
248 FX_DWORD dwRet = SetEncryptHandler(); 247 Error eRet = SetEncryptHandler();
249 if (dwRet != PDFPARSE_ERROR_SUCCESS) 248 if (eRet != SUCCESS)
250 return dwRet; 249 return eRet;
251 250
252 m_pDocument->LoadDoc(); 251 m_pDocument->LoadDoc();
253 if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) { 252 if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) {
254 if (bXRefRebuilt) 253 if (bXRefRebuilt)
255 return PDFPARSE_ERROR_FORMAT; 254 return FORMAT_ERROR;
256 255
257 ReleaseEncryptHandler(); 256 ReleaseEncryptHandler();
258 if (!RebuildCrossRef()) 257 if (!RebuildCrossRef())
259 return PDFPARSE_ERROR_FORMAT; 258 return FORMAT_ERROR;
260 259
261 dwRet = SetEncryptHandler(); 260 eRet = SetEncryptHandler();
262 if (dwRet != PDFPARSE_ERROR_SUCCESS) 261 if (eRet != SUCCESS)
263 return dwRet; 262 return eRet;
264 263
265 m_pDocument->LoadDoc(); 264 m_pDocument->LoadDoc();
266 if (!m_pDocument->GetRoot()) 265 if (!m_pDocument->GetRoot())
267 return PDFPARSE_ERROR_FORMAT; 266 return FORMAT_ERROR;
268 } 267 }
269 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), 268 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(),
270 sizeof(FX_FILESIZE), CompareFileSize); 269 sizeof(FX_FILESIZE), CompareFileSize);
271 if (GetRootObjNum() == 0) { 270 if (GetRootObjNum() == 0) {
272 ReleaseEncryptHandler(); 271 ReleaseEncryptHandler();
273 if (!RebuildCrossRef() || GetRootObjNum() == 0) 272 if (!RebuildCrossRef() || GetRootObjNum() == 0)
274 return PDFPARSE_ERROR_FORMAT; 273 return FORMAT_ERROR;
275 274
276 dwRet = SetEncryptHandler(); 275 eRet = SetEncryptHandler();
277 if (dwRet != PDFPARSE_ERROR_SUCCESS) 276 if (eRet != SUCCESS)
278 return dwRet; 277 return eRet;
279 } 278 }
280 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) { 279 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) {
281 CPDF_Reference* pMetadata = 280 CPDF_Reference* pMetadata =
282 ToReference(m_pDocument->GetRoot()->GetElement("Metadata")); 281 ToReference(m_pDocument->GetRoot()->GetElement("Metadata"));
283 if (pMetadata) 282 if (pMetadata)
284 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); 283 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum();
285 } 284 }
286 return PDFPARSE_ERROR_SUCCESS; 285 return SUCCESS;
287 } 286 }
288 FX_DWORD CPDF_Parser::SetEncryptHandler() { 287 CPDF_Parser::Error CPDF_Parser::SetEncryptHandler() {
289 ReleaseEncryptHandler(); 288 ReleaseEncryptHandler();
290 SetEncryptDictionary(NULL); 289 SetEncryptDictionary(NULL);
291 if (!m_pTrailer) { 290 if (!m_pTrailer) {
292 return PDFPARSE_ERROR_FORMAT; 291 return FORMAT_ERROR;
293 } 292 }
294 CPDF_Object* pEncryptObj = m_pTrailer->GetElement("Encrypt"); 293 CPDF_Object* pEncryptObj = m_pTrailer->GetElement("Encrypt");
295 if (pEncryptObj) { 294 if (pEncryptObj) {
296 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { 295 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) {
297 SetEncryptDictionary(pEncryptDict); 296 SetEncryptDictionary(pEncryptDict);
298 } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) { 297 } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) {
299 pEncryptObj = m_pDocument->GetIndirectObject(pRef->GetRefObjNum()); 298 pEncryptObj = m_pDocument->GetIndirectObject(pRef->GetRefObjNum());
300 if (pEncryptObj) 299 if (pEncryptObj)
301 SetEncryptDictionary(pEncryptObj->GetDict()); 300 SetEncryptDictionary(pEncryptObj->GetDict());
302 } 301 }
303 } 302 }
304 if (m_bForceUseSecurityHandler) { 303 if (m_bForceUseSecurityHandler) {
305 FX_DWORD err = PDFPARSE_ERROR_HANDLER;
306 if (!m_pSecurityHandler) { 304 if (!m_pSecurityHandler) {
307 return PDFPARSE_ERROR_HANDLER; 305 return HANDLER_ERROR;
308 } 306 }
309 if (!m_pSecurityHandler->OnInit(this, m_pEncryptDict)) { 307 if (!m_pSecurityHandler->OnInit(this, m_pEncryptDict)) {
310 return err; 308 return HANDLER_ERROR;
311 } 309 }
312 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler( 310 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler(
313 m_pSecurityHandler->CreateCryptoHandler()); 311 m_pSecurityHandler->CreateCryptoHandler());
314 if (!pCryptoHandler->Init(m_pEncryptDict, m_pSecurityHandler.get())) { 312 if (!pCryptoHandler->Init(m_pEncryptDict, m_pSecurityHandler.get())) {
315 return PDFPARSE_ERROR_HANDLER; 313 return HANDLER_ERROR;
316 } 314 }
317 m_Syntax.SetEncrypt(pCryptoHandler.release()); 315 m_Syntax.SetEncrypt(pCryptoHandler.release());
318 } else if (m_pEncryptDict) { 316 } else if (m_pEncryptDict) {
319 CFX_ByteString filter = m_pEncryptDict->GetString("Filter"); 317 CFX_ByteString filter = m_pEncryptDict->GetString("Filter");
320 std::unique_ptr<CPDF_SecurityHandler> pSecurityHandler; 318 std::unique_ptr<CPDF_SecurityHandler> pSecurityHandler;
321 FX_DWORD err = PDFPARSE_ERROR_HANDLER; 319 Error err = HANDLER_ERROR;
322 if (filter == "Standard") { 320 if (filter == "Standard") {
323 pSecurityHandler.reset(FPDF_CreateStandardSecurityHandler()); 321 pSecurityHandler.reset(FPDF_CreateStandardSecurityHandler());
324 err = PDFPARSE_ERROR_PASSWORD; 322 err = PASSWORD_ERROR;
325 } 323 }
326 if (!pSecurityHandler) { 324 if (!pSecurityHandler) {
327 return PDFPARSE_ERROR_HANDLER; 325 return HANDLER_ERROR;
328 } 326 }
329 if (!pSecurityHandler->OnInit(this, m_pEncryptDict)) { 327 if (!pSecurityHandler->OnInit(this, m_pEncryptDict)) {
330 return err; 328 return err;
331 } 329 }
332 m_pSecurityHandler = std::move(pSecurityHandler); 330 m_pSecurityHandler = std::move(pSecurityHandler);
333 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler( 331 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler(
334 m_pSecurityHandler->CreateCryptoHandler()); 332 m_pSecurityHandler->CreateCryptoHandler());
335 if (!pCryptoHandler->Init(m_pEncryptDict, m_pSecurityHandler.get())) { 333 if (!pCryptoHandler->Init(m_pEncryptDict, m_pSecurityHandler.get())) {
336 return PDFPARSE_ERROR_HANDLER; 334 return HANDLER_ERROR;
337 } 335 }
338 m_Syntax.SetEncrypt(pCryptoHandler.release()); 336 m_Syntax.SetEncrypt(pCryptoHandler.release());
339 } 337 }
340 return PDFPARSE_ERROR_SUCCESS; 338 return SUCCESS;
341 } 339 }
342 void CPDF_Parser::ReleaseEncryptHandler() { 340 void CPDF_Parser::ReleaseEncryptHandler() {
343 m_Syntax.m_pCryptoHandler.reset(); 341 m_Syntax.m_pCryptoHandler.reset();
344 if (!m_bForceUseSecurityHandler) { 342 if (!m_bForceUseSecurityHandler) {
345 m_pSecurityHandler.reset(); 343 m_pSecurityHandler.reset();
346 } 344 }
347 } 345 }
348 346
349 FX_FILESIZE CPDF_Parser::GetObjectOffset(FX_DWORD objnum) const { 347 FX_FILESIZE CPDF_Parser::GetObjectOffset(FX_DWORD objnum) const {
350 if (!IsValidObjectNumber(objnum)) 348 if (!IsValidObjectNumber(objnum))
(...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 1553
1556 if (CPDF_Number* pTable = ToNumber(pDict->GetElement("T"))) 1554 if (CPDF_Number* pTable = ToNumber(pDict->GetElement("T")))
1557 m_LastXRefOffset = pTable->GetInteger(); 1555 m_LastXRefOffset = pTable->GetInteger();
1558 1556
1559 return TRUE; 1557 return TRUE;
1560 } 1558 }
1561 m_pLinearized->Release(); 1559 m_pLinearized->Release();
1562 m_pLinearized = NULL; 1560 m_pLinearized = NULL;
1563 return FALSE; 1561 return FALSE;
1564 } 1562 }
1565 FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess, 1563 CPDF_Parser::Error CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess,
1566 FX_BOOL bReParse, 1564 FX_BOOL bReParse,
1567 FX_BOOL bOwnFileRead) { 1565 FX_BOOL bOwnFileRead) {
1568 CloseParser(bReParse); 1566 CloseParser(bReParse);
1569 m_bXRefStream = FALSE; 1567 m_bXRefStream = FALSE;
1570 m_LastXRefOffset = 0; 1568 m_LastXRefOffset = 0;
1571 m_bOwnFileRead = bOwnFileRead; 1569 m_bOwnFileRead = bOwnFileRead;
1572 int32_t offset = GetHeaderOffset(pFileAccess); 1570 int32_t offset = GetHeaderOffset(pFileAccess);
1573 if (offset == -1) { 1571 if (offset == -1) {
1574 return PDFPARSE_ERROR_FORMAT; 1572 return FORMAT_ERROR;
1575 } 1573 }
1576 if (!IsLinearizedFile(pFileAccess, offset)) { 1574 if (!IsLinearizedFile(pFileAccess, offset)) {
1577 m_Syntax.m_pFileAccess = NULL; 1575 m_Syntax.m_pFileAccess = NULL;
1578 return StartParse(pFileAccess, bReParse, bOwnFileRead); 1576 return StartParse(pFileAccess, bReParse, bOwnFileRead);
1579 } 1577 }
1580 if (!bReParse) { 1578 if (!bReParse) {
1581 m_pDocument = new CPDF_Document(this); 1579 m_pDocument = new CPDF_Document(this);
1582 } 1580 }
1583 FX_FILESIZE dwFirstXRefOffset = m_Syntax.SavePos(); 1581 FX_FILESIZE dwFirstXRefOffset = m_Syntax.SavePos();
1584 FX_BOOL bXRefRebuilt = FALSE; 1582 FX_BOOL bXRefRebuilt = FALSE;
1585 FX_BOOL bLoadV4 = FALSE; 1583 FX_BOOL bLoadV4 = FALSE;
1586 if (!(bLoadV4 = LoadCrossRefV4(dwFirstXRefOffset, 0, FALSE)) && 1584 if (!(bLoadV4 = LoadCrossRefV4(dwFirstXRefOffset, 0, FALSE)) &&
1587 !LoadCrossRefV5(&dwFirstXRefOffset, TRUE)) { 1585 !LoadCrossRefV5(&dwFirstXRefOffset, TRUE)) {
1588 if (!RebuildCrossRef()) { 1586 if (!RebuildCrossRef()) {
1589 return PDFPARSE_ERROR_FORMAT; 1587 return FORMAT_ERROR;
1590 } 1588 }
1591 bXRefRebuilt = TRUE; 1589 bXRefRebuilt = TRUE;
1592 m_LastXRefOffset = 0; 1590 m_LastXRefOffset = 0;
1593 } 1591 }
1594 if (bLoadV4) { 1592 if (bLoadV4) {
1595 m_pTrailer = LoadTrailerV4(); 1593 m_pTrailer = LoadTrailerV4();
1596 if (!m_pTrailer) { 1594 if (!m_pTrailer) {
1597 return PDFPARSE_ERROR_SUCCESS; 1595 return SUCCESS;
1598 } 1596 }
1599 1597
1600 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); 1598 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size");
1601 if (xrefsize > 0) { 1599 if (xrefsize > 0) {
1602 ShrinkObjectMap(xrefsize); 1600 ShrinkObjectMap(xrefsize);
1603 m_V5Type.SetSize(xrefsize); 1601 m_V5Type.SetSize(xrefsize);
1604 } 1602 }
1605 } 1603 }
1606 FX_DWORD dwRet = SetEncryptHandler(); 1604 Error eRet = SetEncryptHandler();
1607 if (dwRet != PDFPARSE_ERROR_SUCCESS) { 1605 if (eRet != SUCCESS) {
1608 return dwRet; 1606 return eRet;
1609 } 1607 }
1610 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict()); 1608 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict());
1611 if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) { 1609 if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) {
1612 if (bXRefRebuilt) { 1610 if (bXRefRebuilt) {
1613 return PDFPARSE_ERROR_FORMAT; 1611 return FORMAT_ERROR;
1614 } 1612 }
1615 ReleaseEncryptHandler(); 1613 ReleaseEncryptHandler();
1616 if (!RebuildCrossRef()) { 1614 if (!RebuildCrossRef()) {
1617 return PDFPARSE_ERROR_FORMAT; 1615 return FORMAT_ERROR;
1618 } 1616 }
1619 dwRet = SetEncryptHandler(); 1617 eRet = SetEncryptHandler();
1620 if (dwRet != PDFPARSE_ERROR_SUCCESS) { 1618 if (eRet != SUCCESS) {
1621 return dwRet; 1619 return eRet;
1622 } 1620 }
1623 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict()); 1621 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict());
1624 if (!m_pDocument->GetRoot()) { 1622 if (!m_pDocument->GetRoot()) {
1625 return PDFPARSE_ERROR_FORMAT; 1623 return FORMAT_ERROR;
1626 } 1624 }
1627 } 1625 }
1628 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), 1626 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(),
1629 sizeof(FX_FILESIZE), CompareFileSize); 1627 sizeof(FX_FILESIZE), CompareFileSize);
1630 if (GetRootObjNum() == 0) { 1628 if (GetRootObjNum() == 0) {
1631 ReleaseEncryptHandler(); 1629 ReleaseEncryptHandler();
1632 if (!RebuildCrossRef() || GetRootObjNum() == 0) 1630 if (!RebuildCrossRef() || GetRootObjNum() == 0)
1633 return PDFPARSE_ERROR_FORMAT; 1631 return FORMAT_ERROR;
1634 1632
1635 dwRet = SetEncryptHandler(); 1633 eRet = SetEncryptHandler();
1636 if (dwRet != PDFPARSE_ERROR_SUCCESS) { 1634 if (eRet != SUCCESS) {
1637 return dwRet; 1635 return eRet;
1638 } 1636 }
1639 } 1637 }
1640 if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) { 1638 if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) {
1641 if (CPDF_Reference* pMetadata = 1639 if (CPDF_Reference* pMetadata =
1642 ToReference(m_pDocument->GetRoot()->GetElement("Metadata"))) 1640 ToReference(m_pDocument->GetRoot()->GetElement("Metadata")))
1643 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); 1641 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum();
1644 } 1642 }
1645 return PDFPARSE_ERROR_SUCCESS; 1643 return SUCCESS;
1646 } 1644 }
1647 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) { 1645 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) {
1648 if (!LoadCrossRefV5(&xrefpos, FALSE)) { 1646 if (!LoadCrossRefV5(&xrefpos, FALSE)) {
1649 return FALSE; 1647 return FALSE;
1650 } 1648 }
1651 std::set<FX_FILESIZE> seen_xrefpos; 1649 std::set<FX_FILESIZE> seen_xrefpos;
1652 while (xrefpos) { 1650 while (xrefpos) {
1653 seen_xrefpos.insert(xrefpos); 1651 seen_xrefpos.insert(xrefpos);
1654 if (!LoadCrossRefV5(&xrefpos, FALSE)) { 1652 if (!LoadCrossRefV5(&xrefpos, FALSE)) {
1655 return FALSE; 1653 return FALSE;
1656 } 1654 }
1657 // Check for circular references. 1655 // Check for circular references.
1658 if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) { 1656 if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) {
1659 return FALSE; 1657 return FALSE;
1660 } 1658 }
1661 } 1659 }
1662 m_ObjectStreamMap.clear(); 1660 m_ObjectStreamMap.clear();
1663 m_bXRefStream = TRUE; 1661 m_bXRefStream = TRUE;
1664 return TRUE; 1662 return TRUE;
1665 } 1663 }
1666 FX_DWORD CPDF_Parser::LoadLinearizedMainXRefTable() { 1664
1665 CPDF_Parser::Error CPDF_Parser::LoadLinearizedMainXRefTable() {
1667 FX_DWORD dwSaveMetadataObjnum = m_Syntax.m_MetadataObjnum; 1666 FX_DWORD dwSaveMetadataObjnum = m_Syntax.m_MetadataObjnum;
1668 m_Syntax.m_MetadataObjnum = 0; 1667 m_Syntax.m_MetadataObjnum = 0;
1669 if (m_pTrailer) { 1668 if (m_pTrailer) {
1670 m_pTrailer->Release(); 1669 m_pTrailer->Release();
1671 m_pTrailer = NULL; 1670 m_pTrailer = NULL;
1672 } 1671 }
1673 m_Syntax.RestorePos(m_LastXRefOffset - m_Syntax.m_HeaderOffset); 1672 m_Syntax.RestorePos(m_LastXRefOffset - m_Syntax.m_HeaderOffset);
1674 uint8_t ch = 0; 1673 uint8_t ch = 0;
1675 FX_DWORD dwCount = 0; 1674 FX_DWORD dwCount = 0;
1676 m_Syntax.GetNextChar(ch); 1675 m_Syntax.GetNextChar(ch);
1677 while (PDFCharIsWhitespace(ch)) { 1676 while (PDFCharIsWhitespace(ch)) {
1678 ++dwCount; 1677 ++dwCount;
1679 if (m_Syntax.m_FileLen >= 1678 if (m_Syntax.m_FileLen >=
1680 (FX_FILESIZE)(m_Syntax.SavePos() + m_Syntax.m_HeaderOffset)) { 1679 (FX_FILESIZE)(m_Syntax.SavePos() + m_Syntax.m_HeaderOffset)) {
1681 break; 1680 break;
1682 } 1681 }
1683 m_Syntax.GetNextChar(ch); 1682 m_Syntax.GetNextChar(ch);
1684 } 1683 }
1685 m_LastXRefOffset += dwCount; 1684 m_LastXRefOffset += dwCount;
1686 m_ObjectStreamMap.clear(); 1685 m_ObjectStreamMap.clear();
1687 m_ObjCache.clear(); 1686 m_ObjCache.clear();
1688 1687
1689 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && 1688 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) &&
1690 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { 1689 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) {
1691 m_LastXRefOffset = 0; 1690 m_LastXRefOffset = 0;
1692 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum; 1691 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum;
1693 return PDFPARSE_ERROR_FORMAT; 1692 return FORMAT_ERROR;
1694 } 1693 }
1695 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), 1694 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(),
1696 sizeof(FX_FILESIZE), CompareFileSize); 1695 sizeof(FX_FILESIZE), CompareFileSize);
1697 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum; 1696 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum;
1698 return PDFPARSE_ERROR_SUCCESS; 1697 return SUCCESS;
1699 } 1698 }
1700 1699
1701 // static 1700 // static
1702 int CPDF_SyntaxParser::s_CurrentRecursionDepth = 0; 1701 int CPDF_SyntaxParser::s_CurrentRecursionDepth = 0;
1703 1702
1704 CPDF_SyntaxParser::CPDF_SyntaxParser() { 1703 CPDF_SyntaxParser::CPDF_SyntaxParser() {
1705 m_pFileAccess = NULL; 1704 m_pFileAccess = NULL;
1706 m_pFileBuf = NULL; 1705 m_pFileBuf = NULL;
1707 m_BufSize = CPDF_ModuleMgr::kFileBufSize; 1706 m_BufSize = CPDF_ModuleMgr::kFileBufSize;
1708 m_pFileBuf = NULL; 1707 m_pFileBuf = NULL;
(...skipping 2492 matching lines...) Expand 10 before | Expand all | Expand 10 after
4201 FX_SAFE_DWORD data_size = m_dwFileLen; 4200 FX_SAFE_DWORD data_size = m_dwFileLen;
4202 data_size -= m_dwLastXRefOffset; 4201 data_size -= m_dwLastXRefOffset;
4203 if (!data_size.IsValid()) { 4202 if (!data_size.IsValid()) {
4204 return DataError; 4203 return DataError;
4205 } 4204 }
4206 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, 4205 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset,
4207 data_size.ValueOrDie())) { 4206 data_size.ValueOrDie())) {
4208 pHints->AddSegment(m_dwLastXRefOffset, data_size.ValueOrDie()); 4207 pHints->AddSegment(m_dwLastXRefOffset, data_size.ValueOrDie());
4209 return DataNotAvailable; 4208 return DataNotAvailable;
4210 } 4209 }
4211 FX_DWORD dwRet = m_pDocument->GetParser()->LoadLinearizedMainXRefTable(); 4210 CPDF_Parser::Error eRet =
4211 m_pDocument->GetParser()->LoadLinearizedMainXRefTable();
4212 m_bMainXRefLoadTried = TRUE; 4212 m_bMainXRefLoadTried = TRUE;
4213 if (dwRet != PDFPARSE_ERROR_SUCCESS) { 4213 if (eRet != CPDF_Parser::SUCCESS) {
4214 return DataError; 4214 return DataError;
4215 } 4215 }
4216 if (!PreparePageItem()) { 4216 if (!PreparePageItem()) {
4217 return DataNotAvailable; 4217 return DataNotAvailable;
4218 } 4218 }
4219 m_bMainXRefLoadedOK = TRUE; 4219 m_bMainXRefLoadedOK = TRUE;
4220 m_bLinearedDataOK = TRUE; 4220 m_bLinearedDataOK = TRUE;
4221 } 4221 }
4222 4222
4223 return m_bLinearedDataOK ? DataAvailable : DataNotAvailable; 4223 return m_bLinearedDataOK ? DataAvailable : DataNotAvailable;
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
4887 if (!m_pLinearizedDict) 4887 if (!m_pLinearizedDict)
4888 return -1; 4888 return -1;
4889 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); 4889 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H");
4890 if (!pRange) 4890 if (!pRange)
4891 return -1; 4891 return -1;
4892 CPDF_Object* pStreamLen = pRange->GetElementValue(1); 4892 CPDF_Object* pStreamLen = pRange->GetElementValue(1);
4893 if (!pStreamLen) 4893 if (!pStreamLen)
4894 return -1; 4894 return -1;
4895 return pStreamLen->GetInteger(); 4895 return pStreamLen->GetInteger();
4896 } 4896 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698