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

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

Issue 1410673005: Add type cast definitions for CPDF_Number. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp ('k') | core/src/fpdfdoc/doc_basic.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 27 matching lines...) Expand all
38 38
39 if (*(FX_DWORD*)buf == tag) 39 if (*(FX_DWORD*)buf == tag)
40 return offset; 40 return offset;
41 41
42 ++offset; 42 ++offset;
43 } 43 }
44 return -1; 44 return -1;
45 } 45 }
46 46
47 int32_t GetDirectInteger(CPDF_Dictionary* pDict, const CFX_ByteStringC& key) { 47 int32_t GetDirectInteger(CPDF_Dictionary* pDict, const CFX_ByteStringC& key) {
48 CPDF_Object* pObj = pDict->GetElement(key); 48 CPDF_Number* pObj = ToNumber(pDict->GetElement(key));
49 if (pObj && (pObj->GetType() == PDFOBJ_NUMBER)) 49 return pObj ? pObj->GetInteger() : 0;
50 return ((CPDF_Number*)pObj)->GetInteger();
51 return 0;
52 } 50 }
53 51
54 bool CheckDirectType(CPDF_Dictionary* pDict, 52 bool CheckDirectType(CPDF_Dictionary* pDict,
55 const CFX_ByteStringC& key, 53 const CFX_ByteStringC& key,
56 int32_t iType) { 54 int32_t iType) {
57 CPDF_Object* pObj = pDict->GetElement(key); 55 CPDF_Object* pObj = pDict->GetElement(key);
58 return !pObj || pObj->GetType() == iType; 56 return !pObj || pObj->GetType() == iType;
59 } 57 }
60 58
61 FX_DWORD GetVarInt(const uint8_t* p, int32_t n) { 59 FX_DWORD GetVarInt(const uint8_t* p, int32_t n) {
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 } else { 1039 } else {
1042 m_Trailers.Add(ToDictionary(pStream->GetDict()->Clone())); 1040 m_Trailers.Add(ToDictionary(pStream->GetDict()->Clone()));
1043 } 1041 }
1044 std::vector<std::pair<int32_t, int32_t> > arrIndex; 1042 std::vector<std::pair<int32_t, int32_t> > arrIndex;
1045 CPDF_Array* pArray = pStream->GetDict()->GetArray(FX_BSTRC("Index")); 1043 CPDF_Array* pArray = pStream->GetDict()->GetArray(FX_BSTRC("Index"));
1046 if (pArray) { 1044 if (pArray) {
1047 FX_DWORD nPairSize = pArray->GetCount() / 2; 1045 FX_DWORD nPairSize = pArray->GetCount() / 2;
1048 for (FX_DWORD i = 0; i < nPairSize; i++) { 1046 for (FX_DWORD i = 0; i < nPairSize; i++) {
1049 CPDF_Object* pStartNumObj = pArray->GetElement(i * 2); 1047 CPDF_Object* pStartNumObj = pArray->GetElement(i * 2);
1050 CPDF_Object* pCountObj = pArray->GetElement(i * 2 + 1); 1048 CPDF_Object* pCountObj = pArray->GetElement(i * 2 + 1);
1051 if (pStartNumObj && pStartNumObj->GetType() == PDFOBJ_NUMBER && 1049 if (ToNumber(pStartNumObj) && ToNumber(pCountObj)) {
1052 pCountObj && pCountObj->GetType() == PDFOBJ_NUMBER) {
1053 int nStartNum = pStartNumObj->GetInteger(); 1050 int nStartNum = pStartNumObj->GetInteger();
1054 int nCount = pCountObj->GetInteger(); 1051 int nCount = pCountObj->GetInteger();
1055 if (nStartNum >= 0 && nCount > 0) { 1052 if (nStartNum >= 0 && nCount > 0) {
1056 arrIndex.push_back(std::make_pair(nStartNum, nCount)); 1053 arrIndex.push_back(std::make_pair(nStartNum, nCount));
1057 } 1054 }
1058 } 1055 }
1059 } 1056 }
1060 } 1057 }
1061 if (arrIndex.size() == 0) { 1058 if (arrIndex.size() == 0) {
1062 arrIndex.push_back(std::make_pair(0, size)); 1059 arrIndex.push_back(std::make_pair(0, size));
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 } 1541 }
1545 FX_DWORD gennum = FXSYS_atoi(word); 1542 FX_DWORD gennum = FXSYS_atoi(word);
1546 if (m_Syntax.GetKeyword() != FX_BSTRC("obj")) { 1543 if (m_Syntax.GetKeyword() != FX_BSTRC("obj")) {
1547 m_Syntax.RestorePos(SavedPos); 1544 m_Syntax.RestorePos(SavedPos);
1548 return FALSE; 1545 return FALSE;
1549 } 1546 }
1550 m_pLinearized = m_Syntax.GetObject(NULL, objnum, gennum, 0); 1547 m_pLinearized = m_Syntax.GetObject(NULL, objnum, gennum, 0);
1551 if (!m_pLinearized) { 1548 if (!m_pLinearized) {
1552 return FALSE; 1549 return FALSE;
1553 } 1550 }
1554 if (m_pLinearized->GetDict() && 1551
1555 m_pLinearized->GetDict()->GetElement(FX_BSTRC("Linearized"))) { 1552 CPDF_Dictionary* pDict = m_pLinearized->GetDict();
1553 if (pDict && pDict->GetElement(FX_BSTRC("Linearized"))) {
1556 m_Syntax.GetNextWord(bIsNumber); 1554 m_Syntax.GetNextWord(bIsNumber);
1557 CPDF_Object* pLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L")); 1555
1556 CPDF_Object* pLen = pDict->GetElement(FX_BSTRC("L"));
1558 if (!pLen) { 1557 if (!pLen) {
1559 m_pLinearized->Release(); 1558 m_pLinearized->Release();
1560 m_pLinearized = NULL; 1559 m_pLinearized = NULL;
1561 return FALSE; 1560 return FALSE;
1562 } 1561 }
1563 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) { 1562 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) {
1564 return FALSE; 1563 return FALSE;
1565 } 1564 }
1566 CPDF_Object* pNo = m_pLinearized->GetDict()->GetElement(FX_BSTRC("P")); 1565
1567 if (pNo && pNo->GetType() == PDFOBJ_NUMBER) { 1566 if (CPDF_Number* pNo = ToNumber(pDict->GetElement(FX_BSTRC("P"))))
1568 m_dwFirstPageNo = pNo->GetInteger(); 1567 m_dwFirstPageNo = pNo->GetInteger();
1569 } 1568
1570 CPDF_Object* pTable = m_pLinearized->GetDict()->GetElement(FX_BSTRC("T")); 1569 if (CPDF_Number* pTable = ToNumber(pDict->GetElement(FX_BSTRC("T"))))
1571 if (pTable && pTable->GetType() == PDFOBJ_NUMBER) {
1572 m_LastXRefOffset = pTable->GetInteger(); 1570 m_LastXRefOffset = pTable->GetInteger();
1573 } 1571
1574 return TRUE; 1572 return TRUE;
1575 } 1573 }
1576 m_pLinearized->Release(); 1574 m_pLinearized->Release();
1577 m_pLinearized = NULL; 1575 m_pLinearized = NULL;
1578 return FALSE; 1576 return FALSE;
1579 } 1577 }
1580 FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess, 1578 FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess,
1581 FX_BOOL bReParse, 1579 FX_BOOL bReParse,
1582 FX_BOOL bOwnFileRead) { 1580 FX_BOOL bOwnFileRead) {
1583 CloseParser(bReParse); 1581 CloseParser(bReParse);
(...skipping 2030 matching lines...) Expand 10 before | Expand all | Expand 10 after
3614 if (!pXRefOffset) { 3612 if (!pXRefOffset) {
3615 m_docStatus = PDF_DATAAVAIL_ERROR; 3613 m_docStatus = PDF_DATAAVAIL_ERROR;
3616 return FALSE; 3614 return FALSE;
3617 } 3615 }
3618 CPDF_Object* pFileLen = pDict ? pDict->GetElement(FX_BSTRC("L")) : NULL; 3616 CPDF_Object* pFileLen = pDict ? pDict->GetElement(FX_BSTRC("L")) : NULL;
3619 if (!pFileLen) { 3617 if (!pFileLen) {
3620 m_docStatus = PDF_DATAAVAIL_ERROR; 3618 m_docStatus = PDF_DATAAVAIL_ERROR;
3621 return FALSE; 3619 return FALSE;
3622 } 3620 }
3623 FX_BOOL bNeedDownLoad = FALSE; 3621 FX_BOOL bNeedDownLoad = FALSE;
3624 if (pEndOffSet->GetType() == PDFOBJ_NUMBER) { 3622 if (pEndOffSet->IsNumber()) {
3625 FX_DWORD dwEnd = pEndOffSet->GetInteger(); 3623 FX_DWORD dwEnd = pEndOffSet->GetInteger();
3626 dwEnd += 512; 3624 dwEnd += 512;
3627 if ((FX_FILESIZE)dwEnd > m_dwFileLen) { 3625 if ((FX_FILESIZE)dwEnd > m_dwFileLen) {
3628 dwEnd = (FX_DWORD)m_dwFileLen; 3626 dwEnd = (FX_DWORD)m_dwFileLen;
3629 } 3627 }
3630 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen); 3628 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen);
3631 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0; 3629 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0;
3632 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) { 3630 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) {
3633 pHints->AddSegment(iStartPos, iSize); 3631 pHints->AddSegment(iStartPos, iSize);
3634 bNeedDownLoad = TRUE; 3632 bNeedDownLoad = TRUE;
3635 } 3633 }
3636 } 3634 }
3637 m_dwLastXRefOffset = 0; 3635 m_dwLastXRefOffset = 0;
3638 FX_FILESIZE dwFileLen = 0; 3636 FX_FILESIZE dwFileLen = 0;
3639 if (pXRefOffset->GetType() == PDFOBJ_NUMBER) { 3637 if (pXRefOffset->IsNumber())
3640 m_dwLastXRefOffset = pXRefOffset->GetInteger(); 3638 m_dwLastXRefOffset = pXRefOffset->GetInteger();
3641 } 3639
3642 if (pFileLen->GetType() == PDFOBJ_NUMBER) { 3640 if (pFileLen->IsNumber())
3643 dwFileLen = pFileLen->GetInteger(); 3641 dwFileLen = pFileLen->GetInteger();
3644 } 3642
3645 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, 3643 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset,
3646 (FX_DWORD)(dwFileLen - m_dwLastXRefOffset))) { 3644 (FX_DWORD)(dwFileLen - m_dwLastXRefOffset))) {
3647 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) { 3645 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) {
3648 FX_DWORD dwSize = (FX_DWORD)(dwFileLen - m_dwLastXRefOffset); 3646 FX_DWORD dwSize = (FX_DWORD)(dwFileLen - m_dwLastXRefOffset);
3649 FX_FILESIZE offset = m_dwLastXRefOffset; 3647 FX_FILESIZE offset = m_dwLastXRefOffset;
3650 if (dwSize < 512 && dwFileLen > 512) { 3648 if (dwSize < 512 && dwFileLen > 512) {
3651 dwSize = 512; 3649 dwSize = 512;
3652 offset = dwFileLen - 512; 3650 offset = dwFileLen - 512;
3653 } 3651 }
3654 pHints->AddSegment(offset, dwSize); 3652 pHints->AddSegment(offset, dwSize);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
3726 FX_DWORD objnum = FXSYS_atoi(wordObjNum); 3724 FX_DWORD objnum = FXSYS_atoi(wordObjNum);
3727 if (m_pLinearized) { 3725 if (m_pLinearized) {
3728 m_pLinearized->Release(); 3726 m_pLinearized->Release();
3729 m_pLinearized = NULL; 3727 m_pLinearized = NULL;
3730 } 3728 }
3731 m_pLinearized = 3729 m_pLinearized =
3732 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum); 3730 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum);
3733 if (!m_pLinearized) { 3731 if (!m_pLinearized) {
3734 return FALSE; 3732 return FALSE;
3735 } 3733 }
3736 if (m_pLinearized->GetDict() && 3734
3737 m_pLinearized->GetDict()->GetElement(FX_BSTRC("Linearized"))) { 3735 CPDF_Dictionary* pDict = m_pLinearized->GetDict();
3738 CPDF_Object* pLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L")); 3736 if (pDict && pDict->GetElement(FX_BSTRC("Linearized"))) {
3737 CPDF_Object* pLen = pDict->GetElement(FX_BSTRC("L"));
3739 if (!pLen) { 3738 if (!pLen) {
3740 return FALSE; 3739 return FALSE;
3741 } 3740 }
3742 if ((FX_FILESIZE)pLen->GetInteger() != m_pFileRead->GetSize()) { 3741 if ((FX_FILESIZE)pLen->GetInteger() != m_pFileRead->GetSize()) {
3743 return FALSE; 3742 return FALSE;
3744 } 3743 }
3745 m_bLinearized = TRUE; 3744 m_bLinearized = TRUE;
3746 CPDF_Object* pNo = m_pLinearized->GetDict()->GetElement(FX_BSTRC("P")); 3745
3747 if (pNo && pNo->GetType() == PDFOBJ_NUMBER) { 3746 if (CPDF_Number* pNo = ToNumber(pDict->GetElement(FX_BSTRC("P"))))
3748 m_dwFirstPageNo = pNo->GetInteger(); 3747 m_dwFirstPageNo = pNo->GetInteger();
3749 } 3748
3750 return TRUE; 3749 return TRUE;
3751 } 3750 }
3752 return FALSE; 3751 return FALSE;
3753 } 3752 }
3754 FX_BOOL CPDF_DataAvail::CheckEnd(IFX_DownloadHints* pHints) { 3753 FX_BOOL CPDF_DataAvail::CheckEnd(IFX_DownloadHints* pHints) {
3755 FX_DWORD req_pos = (FX_DWORD)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); 3754 FX_DWORD req_pos = (FX_DWORD)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0);
3756 FX_DWORD dwSize = (FX_DWORD)(m_dwFileLen - req_pos); 3755 FX_DWORD dwSize = (FX_DWORD)(m_dwFileLen - req_pos);
3757 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { 3756 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) {
3758 uint8_t buffer[1024]; 3757 uint8_t buffer[1024];
3759 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); 3758 m_pFileRead->ReadBlock(buffer, req_pos, dwSize);
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
4616 return FALSE; 4615 return FALSE;
4617 } 4616 }
4618 CPDF_PageNode::~CPDF_PageNode() { 4617 CPDF_PageNode::~CPDF_PageNode() {
4619 int32_t iSize = m_childNode.GetSize(); 4618 int32_t iSize = m_childNode.GetSize();
4620 for (int32_t i = 0; i < iSize; ++i) { 4619 for (int32_t i = 0; i < iSize; ++i) {
4621 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; 4620 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i];
4622 delete pNode; 4621 delete pNode;
4623 } 4622 }
4624 m_childNode.RemoveAll(); 4623 m_childNode.RemoveAll();
4625 } 4624 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp ('k') | core/src/fpdfdoc/doc_basic.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698