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

Side by Side Diff: core/fpdfapi/parser/cpdf_parser.cpp

Issue 2474283005: Revert of Unify some code (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « core/fpdfapi/parser/cpdf_parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "core/fpdfapi/parser/cpdf_array.h" 11 #include "core/fpdfapi/parser/cpdf_array.h"
12 #include "core/fpdfapi/parser/cpdf_crypto_handler.h" 12 #include "core/fpdfapi/parser/cpdf_crypto_handler.h"
13 #include "core/fpdfapi/parser/cpdf_dictionary.h" 13 #include "core/fpdfapi/parser/cpdf_dictionary.h"
14 #include "core/fpdfapi/parser/cpdf_document.h" 14 #include "core/fpdfapi/parser/cpdf_document.h"
15 #include "core/fpdfapi/parser/cpdf_linearized.h"
16 #include "core/fpdfapi/parser/cpdf_number.h" 15 #include "core/fpdfapi/parser/cpdf_number.h"
17 #include "core/fpdfapi/parser/cpdf_reference.h" 16 #include "core/fpdfapi/parser/cpdf_reference.h"
18 #include "core/fpdfapi/parser/cpdf_security_handler.h" 17 #include "core/fpdfapi/parser/cpdf_security_handler.h"
19 #include "core/fpdfapi/parser/cpdf_stream.h" 18 #include "core/fpdfapi/parser/cpdf_stream.h"
20 #include "core/fpdfapi/parser/cpdf_stream_acc.h" 19 #include "core/fpdfapi/parser/cpdf_stream_acc.h"
21 #include "core/fpdfapi/parser/cpdf_syntax_parser.h" 20 #include "core/fpdfapi/parser/cpdf_syntax_parser.h"
22 #include "core/fpdfapi/parser/fpdf_parser_utility.h" 21 #include "core/fpdfapi/parser/fpdf_parser_utility.h"
23 #include "core/fxcrt/fx_ext.h" 22 #include "core/fxcrt/fx_ext.h"
24 #include "core/fxcrt/fx_safe_types.h" 23 #include "core/fxcrt/fx_safe_types.h"
25 #include "third_party/base/stl_util.h" 24 #include "third_party/base/stl_util.h"
(...skipping 22 matching lines...) Expand all
48 } // namespace 47 } // namespace
49 48
50 CPDF_Parser::CPDF_Parser() 49 CPDF_Parser::CPDF_Parser()
51 : m_pDocument(nullptr), 50 : m_pDocument(nullptr),
52 m_bHasParsed(false), 51 m_bHasParsed(false),
53 m_bOwnFileRead(true), 52 m_bOwnFileRead(true),
54 m_FileVersion(0), 53 m_FileVersion(0),
55 m_pTrailer(nullptr), 54 m_pTrailer(nullptr),
56 m_pEncryptDict(nullptr), 55 m_pEncryptDict(nullptr),
57 m_bVersionUpdated(false), 56 m_bVersionUpdated(false),
57 m_pLinearized(nullptr),
58 m_dwFirstPageNo(0),
58 m_dwXrefStartObjNum(0) { 59 m_dwXrefStartObjNum(0) {
59 m_pSyntax.reset(new CPDF_SyntaxParser); 60 m_pSyntax.reset(new CPDF_SyntaxParser);
60 } 61 }
61 62
62 CPDF_Parser::~CPDF_Parser() { 63 CPDF_Parser::~CPDF_Parser() {
63 delete m_pTrailer; 64 delete m_pTrailer;
64 ReleaseEncryptHandler(); 65 ReleaseEncryptHandler();
65 SetEncryptDictionary(nullptr); 66 SetEncryptDictionary(nullptr);
66 67
67 if (m_bOwnFileRead && m_pSyntax->m_pFileAccess) { 68 if (m_bOwnFileRead && m_pSyntax->m_pFileAccess) {
68 m_pSyntax->m_pFileAccess->Release(); 69 m_pSyntax->m_pFileAccess->Release();
69 m_pSyntax->m_pFileAccess = nullptr; 70 m_pSyntax->m_pFileAccess = nullptr;
70 } 71 }
71 72
72 for (CPDF_Dictionary* trailer : m_Trailers) 73 for (CPDF_Dictionary* trailer : m_Trailers)
73 delete trailer; 74 delete trailer;
75
76 delete m_pLinearized;
74 } 77 }
75 78
76 uint32_t CPDF_Parser::GetLastObjNum() const { 79 uint32_t CPDF_Parser::GetLastObjNum() const {
77 return m_ObjectInfo.empty() ? 0 : m_ObjectInfo.rbegin()->first; 80 return m_ObjectInfo.empty() ? 0 : m_ObjectInfo.rbegin()->first;
78 } 81 }
79 82
80 bool CPDF_Parser::IsValidObjectNumber(uint32_t objnum) const { 83 bool CPDF_Parser::IsValidObjectNumber(uint32_t objnum) const {
81 return !m_ObjectInfo.empty() && objnum <= m_ObjectInfo.rbegin()->first; 84 return !m_ObjectInfo.empty() && objnum <= m_ObjectInfo.rbegin()->first;
82 } 85 }
83 86
(...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 } 1395 }
1393 1396
1394 CPDF_Object* pObj = m_pSyntax->GetObjectForStrict(pObjList, objnum, gennum); 1397 CPDF_Object* pObj = m_pSyntax->GetObjectForStrict(pObjList, objnum, gennum);
1395 if (pResultPos) 1398 if (pResultPos)
1396 *pResultPos = m_pSyntax->m_Pos; 1399 *pResultPos = m_pSyntax->m_Pos;
1397 1400
1398 m_pSyntax->RestorePos(SavedPos); 1401 m_pSyntax->RestorePos(SavedPos);
1399 return pObj; 1402 return pObj;
1400 } 1403 }
1401 1404
1402 uint32_t CPDF_Parser::GetFirstPageNo() const {
1403 return m_pLinearized ? m_pLinearized->GetFirstPageNo() : 0;
1404 }
1405
1406 CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() { 1405 CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() {
1407 if (m_pSyntax->GetKeyword() != "trailer") 1406 if (m_pSyntax->GetKeyword() != "trailer")
1408 return nullptr; 1407 return nullptr;
1409 1408
1410 std::unique_ptr<CPDF_Object> pObj( 1409 std::unique_ptr<CPDF_Object> pObj(
1411 m_pSyntax->GetObject(m_pDocument, 0, 0, true)); 1410 m_pSyntax->GetObject(m_pDocument, 0, 0, true));
1412 if (!ToDictionary(pObj.get())) 1411 if (!ToDictionary(pObj.get()))
1413 return nullptr; 1412 return nullptr;
1414 return pObj.release()->AsDictionary(); 1413 return pObj.release()->AsDictionary();
1415 } 1414 }
(...skipping 26 matching lines...) Expand all
1442 word = m_pSyntax->GetNextWord(&bIsNumber); 1441 word = m_pSyntax->GetNextWord(&bIsNumber);
1443 if (!bIsNumber) 1442 if (!bIsNumber)
1444 return false; 1443 return false;
1445 1444
1446 uint32_t gennum = FXSYS_atoui(word.c_str()); 1445 uint32_t gennum = FXSYS_atoui(word.c_str());
1447 if (m_pSyntax->GetKeyword() != "obj") { 1446 if (m_pSyntax->GetKeyword() != "obj") {
1448 m_pSyntax->RestorePos(SavedPos); 1447 m_pSyntax->RestorePos(SavedPos);
1449 return false; 1448 return false;
1450 } 1449 }
1451 1450
1452 m_pLinearized = CPDF_Linearized::CreateForObject( 1451 m_pLinearized = m_pSyntax->GetObject(nullptr, objnum, gennum, true);
1453 pdfium::WrapUnique(m_pSyntax->GetObject(nullptr, objnum, gennum, true)));
1454 if (!m_pLinearized) 1452 if (!m_pLinearized)
1455 return false; 1453 return false;
1456 m_LastXRefOffset = m_pLinearized->GetLastXRefOffset(); 1454
1457 // Move parser onto first page xref table start. 1455 CPDF_Dictionary* pDict = m_pLinearized->GetDict();
1458 m_pSyntax->GetNextWord(nullptr); 1456 if (pDict && pDict->GetObjectFor("Linearized")) {
1459 return true; 1457 m_pSyntax->GetNextWord(nullptr);
1458
1459 CPDF_Object* pLen = pDict->GetObjectFor("L");
1460 if (!pLen) {
1461 delete m_pLinearized;
1462 m_pLinearized = nullptr;
1463 return false;
1464 }
1465
1466 if (pLen->GetInteger() != (int)pFileAccess->GetSize())
1467 return false;
1468
1469 if (CPDF_Number* pNo = ToNumber(pDict->GetObjectFor("P")))
1470 m_dwFirstPageNo = pNo->GetInteger();
1471
1472 if (CPDF_Number* pTable = ToNumber(pDict->GetObjectFor("T")))
1473 m_LastXRefOffset = pTable->GetInteger();
1474
1475 return true;
1476 }
1477 delete m_pLinearized;
1478 m_pLinearized = nullptr;
1479 return false;
1460 } 1480 }
1461 1481
1462 CPDF_Parser::Error CPDF_Parser::StartLinearizedParse( 1482 CPDF_Parser::Error CPDF_Parser::StartLinearizedParse(
1463 IFX_SeekableReadStream* pFileAccess, 1483 IFX_SeekableReadStream* pFileAccess,
1464 CPDF_Document* pDocument) { 1484 CPDF_Document* pDocument) {
1465 ASSERT(!m_bHasParsed); 1485 ASSERT(!m_bHasParsed);
1466 1486
1467 m_bXRefStream = false; 1487 m_bXRefStream = false;
1468 m_LastXRefOffset = 0; 1488 m_LastXRefOffset = 0;
1469 m_bOwnFileRead = true; 1489 m_bOwnFileRead = true;
(...skipping 28 matching lines...) Expand all
1498 1518
1499 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); 1519 int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size");
1500 if (xrefsize > 0) 1520 if (xrefsize > 0)
1501 ShrinkObjectMap(xrefsize); 1521 ShrinkObjectMap(xrefsize);
1502 } 1522 }
1503 1523
1504 Error eRet = SetEncryptHandler(); 1524 Error eRet = SetEncryptHandler();
1505 if (eRet != SUCCESS) 1525 if (eRet != SUCCESS)
1506 return eRet; 1526 return eRet;
1507 1527
1508 m_pDocument->LoadLinearizedDoc(m_pLinearized.get()); 1528 m_pDocument->LoadLinearizedDoc(m_pLinearized->GetDict());
1509 if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) { 1529 if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) {
1510 if (bXRefRebuilt) 1530 if (bXRefRebuilt)
1511 return FORMAT_ERROR; 1531 return FORMAT_ERROR;
1512 1532
1513 ReleaseEncryptHandler(); 1533 ReleaseEncryptHandler();
1514 if (!RebuildCrossRef()) 1534 if (!RebuildCrossRef())
1515 return FORMAT_ERROR; 1535 return FORMAT_ERROR;
1516 1536
1517 eRet = SetEncryptHandler(); 1537 eRet = SetEncryptHandler();
1518 if (eRet != SUCCESS) 1538 if (eRet != SUCCESS)
1519 return eRet; 1539 return eRet;
1520 1540
1521 m_pDocument->LoadLinearizedDoc(m_pLinearized.get()); 1541 m_pDocument->LoadLinearizedDoc(m_pLinearized->GetDict());
1522 if (!m_pDocument->GetRoot()) 1542 if (!m_pDocument->GetRoot())
1523 return FORMAT_ERROR; 1543 return FORMAT_ERROR;
1524 } 1544 }
1525 1545
1526 if (GetRootObjNum() == 0) { 1546 if (GetRootObjNum() == 0) {
1527 ReleaseEncryptHandler(); 1547 ReleaseEncryptHandler();
1528 if (!RebuildCrossRef() || GetRootObjNum() == 0) 1548 if (!RebuildCrossRef() || GetRootObjNum() == 0)
1529 return FORMAT_ERROR; 1549 return FORMAT_ERROR;
1530 1550
1531 eRet = SetEncryptHandler(); 1551 eRet = SetEncryptHandler();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && 1606 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) &&
1587 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { 1607 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) {
1588 m_LastXRefOffset = 0; 1608 m_LastXRefOffset = 0;
1589 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; 1609 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum;
1590 return FORMAT_ERROR; 1610 return FORMAT_ERROR;
1591 } 1611 }
1592 1612
1593 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; 1613 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum;
1594 return SUCCESS; 1614 return SUCCESS;
1595 } 1615 }
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698