summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_parser
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2016-01-05 16:33:12 -0800
committerLei Zhang <thestig@chromium.org>2016-01-05 16:33:12 -0800
commit62664cee15230d6cbe08ed010721a4557b36dc22 (patch)
tree2baf5570b23f51e082f3ab3e8de88d8538043ae3 /core/src/fpdfapi/fpdf_parser
parent6ba32d9e65ef5d40d357876f9457e228a5fab308 (diff)
downloadpdfium-62664cee15230d6cbe08ed010721a4557b36dc22.tar.xz
Merge to XFA: Fix a few uses of default arguments.
TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1555293002 . (cherry picked from commit dbfaa8d11404a53b4807b3dbd0185047367bbff6) Review URL: https://codereview.chromium.org/1565603002 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_parser')
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp21
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp4
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp26
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp56
4 files changed, 58 insertions, 49 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp
index bf94185720..0b41e3f1cc 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp
@@ -34,7 +34,8 @@ CPDF_DocRenderData* CPDF_Document::GetValidateRenderData() {
}
void CPDF_Document::LoadDoc() {
m_LastObjNum = m_pParser->GetLastObjNum();
- CPDF_Object* pRootObj = GetIndirectObject(m_pParser->GetRootObjNum());
+ CPDF_Object* pRootObj =
+ GetIndirectObject(m_pParser->GetRootObjNum(), nullptr);
if (!pRootObj) {
return;
}
@@ -42,7 +43,8 @@ void CPDF_Document::LoadDoc() {
if (!m_pRootDict) {
return;
}
- CPDF_Object* pInfoObj = GetIndirectObject(m_pParser->GetInfoObjNum());
+ CPDF_Object* pInfoObj =
+ GetIndirectObject(m_pParser->GetInfoObjNum(), nullptr);
if (pInfoObj) {
m_pInfoDict = pInfoObj->GetDict();
}
@@ -56,13 +58,14 @@ void CPDF_Document::LoadDoc() {
void CPDF_Document::LoadAsynDoc(CPDF_Dictionary* pLinearized) {
m_bLinearized = TRUE;
m_LastObjNum = m_pParser->GetLastObjNum();
- CPDF_Object* indirectObj = GetIndirectObject(m_pParser->GetRootObjNum());
- m_pRootDict = indirectObj ? indirectObj->GetDict() : NULL;
+ CPDF_Object* pIndirectObj =
+ GetIndirectObject(m_pParser->GetRootObjNum(), nullptr);
+ m_pRootDict = pIndirectObj ? pIndirectObj->GetDict() : nullptr;
if (!m_pRootDict) {
return;
}
- indirectObj = GetIndirectObject(m_pParser->GetInfoObjNum());
- m_pInfoDict = indirectObj ? indirectObj->GetDict() : NULL;
+ pIndirectObj = GetIndirectObject(m_pParser->GetInfoObjNum(), nullptr);
+ m_pInfoDict = pIndirectObj ? pIndirectObj->GetDict() : nullptr;
CPDF_Array* pIDArray = m_pParser->GetIDArray();
if (pIDArray) {
m_ID1 = pIDArray->GetString(0);
@@ -142,14 +145,16 @@ CPDF_Dictionary* CPDF_Document::GetPage(int iPage) {
if (m_bLinearized && (iPage == (int)m_dwFirstPageNo)) {
if (CPDF_Dictionary* pDict =
- ToDictionary(GetIndirectObject(m_dwFirstPageObjNum)))
+ ToDictionary(GetIndirectObject(m_dwFirstPageObjNum, nullptr)))
return pDict;
}
int objnum = m_PageList.GetAt(iPage);
if (objnum) {
- if (CPDF_Dictionary* pDict = ToDictionary(GetIndirectObject(objnum)))
+ if (CPDF_Dictionary* pDict =
+ ToDictionary(GetIndirectObject(objnum, nullptr))) {
return pDict;
+ }
}
CPDF_Dictionary* pRoot = GetRoot();
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp
index df7b7a33cb..d0154d118e 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp
@@ -58,7 +58,7 @@ void CFDF_Document::ParseStream(IFX_FileRead* pFile, FX_BOOL bOwnFile) {
if (word != "obj") {
break;
}
- CPDF_Object* pObj = parser.GetObject(this, objnum, 0, 0);
+ CPDF_Object* pObj = parser.GetObject(this, objnum, 0, nullptr, true);
if (!pObj) {
break;
}
@@ -72,7 +72,7 @@ void CFDF_Document::ParseStream(IFX_FileRead* pFile, FX_BOOL bOwnFile) {
break;
}
if (CPDF_Dictionary* pMainDict =
- ToDictionary(parser.GetObject(this, 0, 0, 0))) {
+ ToDictionary(parser.GetObject(this, 0, 0, nullptr, true))) {
m_pRootDict = pMainDict->GetDict("Root");
pMainDict->Release();
}
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
index b94a6d91b3..b3005a9e83 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
@@ -61,7 +61,7 @@ CFX_ByteString CPDF_Object::GetString() const {
break;
CPDF_Object* pObj =
- pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum());
+ pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum(), nullptr);
return pObj ? pObj->GetString() : CFX_ByteString();
}
}
@@ -83,12 +83,13 @@ CFX_ByteStringC CPDF_Object::GetConstString() const {
break;
CPDF_Object* pObj =
- pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum());
+ pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum(), nullptr);
return pObj ? pObj->GetConstString() : CFX_ByteStringC();
}
}
return CFX_ByteStringC();
}
+
FX_FLOAT CPDF_Object::GetNumber() const {
switch (m_Type) {
case PDFOBJ_NUMBER:
@@ -99,20 +100,22 @@ FX_FLOAT CPDF_Object::GetNumber() const {
break;
CPDF_Object* pObj =
- pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum());
+ pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum(), nullptr);
return pObj ? pObj->GetNumber() : 0;
}
}
return 0;
}
+
FX_FLOAT CPDF_Object::GetNumber16() const {
return GetNumber();
}
+
int CPDF_Object::GetInteger() const {
CFX_AutoRestorer<int> restorer(&s_nCurRefDepth);
- if (++s_nCurRefDepth > OBJECT_REF_MAX_DEPTH) {
+ if (++s_nCurRefDepth > kObjectRefMaxDepth)
return 0;
- }
+
switch (m_Type) {
case PDFOBJ_BOOLEAN:
return AsBoolean()->m_bValue;
@@ -146,7 +149,8 @@ CPDF_Dictionary* CPDF_Object::GetDict() const {
CPDF_IndirectObjects* pIndirect = pRef->GetObjList();
if (!pIndirect)
return nullptr;
- CPDF_Object* pObj = pIndirect->GetIndirectObject(pRef->GetRefObjNum());
+ CPDF_Object* pObj =
+ pIndirect->GetIndirectObject(pRef->GetRefObjNum(), nullptr);
if (!pObj || (pObj == this))
return nullptr;
return pObj->GetDict();
@@ -161,6 +165,7 @@ CPDF_Array* CPDF_Object::GetArray() const {
// See bug #234.
return const_cast<CPDF_Array*>(AsArray());
}
+
void CPDF_Object::SetString(const CFX_ByteString& str) {
switch (m_Type) {
case PDFOBJ_BOOLEAN:
@@ -218,14 +223,16 @@ FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const {
}
return FALSE;
}
+
CPDF_Object* CPDF_Object::GetDirect() const {
const CPDF_Reference* pRef = AsReference();
if (!pRef)
return const_cast<CPDF_Object*>(this);
if (!pRef->m_pObjList)
return nullptr;
- return pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum());
+ return pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum(), nullptr);
}
+
CPDF_Object* CPDF_Object::Clone(FX_BOOL bDirect) const {
std::set<FX_DWORD> visited;
return CloneInternal(bDirect, &visited);
@@ -1089,9 +1096,8 @@ CPDF_IndirectObjects::~CPDF_IndirectObjects() {
static_cast<CPDF_Object*>(value)->Destroy();
}
}
-CPDF_Object* CPDF_IndirectObjects::GetIndirectObject(
- FX_DWORD objnum,
- struct PARSE_CONTEXT* pContext) {
+CPDF_Object* CPDF_IndirectObjects::GetIndirectObject(FX_DWORD objnum,
+ PARSE_CONTEXT* pContext) {
if (objnum == 0)
return nullptr;
void* value;
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index 4aa99d08e3..aaa6fa2f71 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -90,18 +90,11 @@ bool CanReadFromBitStream(const CFX_BitStream* hStream,
using ScopedFileStream =
std::unique_ptr<IFX_FileStream, ReleaseDeleter<IFX_FileStream>>;
-FX_BOOL IsSignatureDict(const CPDF_Dictionary* pDict) {
+bool IsSignatureDict(const CPDF_Dictionary* pDict) {
CPDF_Object* pType = pDict->GetElementValue("Type");
- if (!pType) {
+ if (!pType)
pType = pDict->GetElementValue("FT");
- if (!pType) {
- return FALSE;
- }
- }
- if (pType->GetString() == "Sig") {
- return TRUE;
- }
- return FALSE;
+ return pType && pType->GetString() == "Sig";
}
CPDF_Parser::CPDF_Parser() {
@@ -294,7 +287,8 @@ FX_DWORD CPDF_Parser::SetEncryptHandler() {
if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) {
SetEncryptDictionary(pEncryptDict);
} else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) {
- pEncryptObj = m_pDocument->GetIndirectObject(pRef->GetRefObjNum());
+ pEncryptObj =
+ m_pDocument->GetIndirectObject(pRef->GetRefObjNum(), nullptr);
if (pEncryptObj)
SetEncryptDictionary(pEncryptObj->GetDict());
}
@@ -844,7 +838,8 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
if (PDFCharIsWhitespace(byte) || PDFCharIsDelimiter(byte)) {
last_trailer = pos + i - 7;
m_Syntax.RestorePos(pos + i - m_Syntax.m_HeaderOffset);
- CPDF_Object* pObj = m_Syntax.GetObject(m_pDocument, 0, 0, 0);
+ CPDF_Object* pObj =
+ m_Syntax.GetObject(m_pDocument, 0, 0, nullptr, true);
if (pObj) {
if (!pObj->IsDictionary() && !pObj->AsStream()) {
pObj->Release();
@@ -1228,7 +1223,7 @@ CPDF_Object* CPDF_Parser::ParseIndirectObject(CPDF_IndirectObjects* pObjList,
return nullptr;
syntax.RestorePos(offset + it->second);
- return syntax.GetObject(pObjList, 0, 0, pContext);
+ return syntax.GetObject(pObjList, 0, 0, pContext, true);
}
CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) {
@@ -1236,8 +1231,8 @@ CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) {
if (m_ObjectStreamMap.Lookup((void*)(uintptr_t)objnum, (void*&)pStreamAcc))
return pStreamAcc;
- const CPDF_Stream* pStream =
- ToStream(m_pDocument ? m_pDocument->GetIndirectObject(objnum) : nullptr);
+ const CPDF_Stream* pStream = ToStream(
+ m_pDocument ? m_pDocument->GetIndirectObject(objnum, nullptr) : nullptr);
if (!pStream)
return nullptr;
@@ -1412,7 +1407,7 @@ CPDF_Object* CPDF_Parser::ParseIndirectObjectAt(CPDF_IndirectObjects* pObjList,
return NULL;
}
CPDF_Object* pObj =
- m_Syntax.GetObject(pObjList, objnum, parser_gennum, pContext);
+ m_Syntax.GetObject(pObjList, objnum, parser_gennum, pContext, true);
m_Syntax.SavePos();
CFX_ByteString bsWord = m_Syntax.GetKeyword();
if (bsWord == "endobj") {
@@ -1431,7 +1426,7 @@ CPDF_Object* CPDF_Parser::ParseIndirectObjectAtByStrict(
CPDF_IndirectObjects* pObjList,
FX_FILESIZE pos,
FX_DWORD objnum,
- struct PARSE_CONTEXT* pContext,
+ PARSE_CONTEXT* pContext,
FX_FILESIZE* pResultPos) {
FX_FILESIZE SavedPos = m_Syntax.SavePos();
m_Syntax.RestorePos(pos);
@@ -1470,7 +1465,7 @@ CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() {
return nullptr;
std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj(
- m_Syntax.GetObject(m_pDocument, 0, 0, 0));
+ m_Syntax.GetObject(m_pDocument, 0, 0, nullptr, true));
if (!ToDictionary(pObj.get()))
return nullptr;
return pObj.release()->AsDictionary();
@@ -1523,7 +1518,7 @@ FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess,
m_Syntax.RestorePos(SavedPos);
return FALSE;
}
- m_pLinearized = m_Syntax.GetObject(NULL, objnum, gennum, 0);
+ m_pLinearized = m_Syntax.GetObject(nullptr, objnum, gennum, nullptr, true);
if (!m_pLinearized) {
return FALSE;
}
@@ -2089,9 +2084,10 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList,
if (bTypeOnly)
return (CPDF_Object*)PDFOBJ_ARRAY;
CPDF_Array* pArray = new CPDF_Array;
- while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum))
+ while (CPDF_Object* pObj =
+ GetObject(pObjList, objnum, gennum, nullptr, true)) {
pArray->Add(pObj);
-
+ }
return pArray;
}
if (word[0] == '/') {
@@ -2136,7 +2132,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList,
if (key == "/Contents")
dwSignValuePos = m_Pos;
- CPDF_Object* pObj = GetObject(pObjList, objnum, gennum);
+ CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, nullptr, true);
if (!pObj)
continue;
@@ -2153,7 +2149,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList,
if (IsSignatureDict(pDict.get())) {
FX_FILESIZE dwSavePos = m_Pos;
m_Pos = dwSignValuePos;
- CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, NULL, FALSE);
+ CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, nullptr, FALSE);
pDict->SetAt("Contents", pObj);
m_Pos = dwSavePos;
}
@@ -2187,7 +2183,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(
CPDF_IndirectObjects* pObjList,
FX_DWORD objnum,
FX_DWORD gennum,
- struct PARSE_CONTEXT* pContext) {
+ PARSE_CONTEXT* pContext) {
CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth);
if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) {
return NULL;
@@ -2249,8 +2245,10 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(
return (CPDF_Object*)PDFOBJ_ARRAY;
std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray(
new CPDF_Array);
- while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum))
+ while (CPDF_Object* pObj =
+ GetObject(pObjList, objnum, gennum, nullptr, true)) {
pArray->Add(pObj);
+ }
return m_WordBuffer[0] == ']' ? pArray.release() : nullptr;
}
if (word[0] == '/') {
@@ -2286,7 +2284,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(
key = PDF_NameDecode(key);
std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> obj(
- GetObject(pObjList, objnum, gennum));
+ GetObject(pObjList, objnum, gennum, nullptr, true));
if (!obj) {
uint8_t ch;
while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) {
@@ -3062,7 +3060,7 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail(
} else if (!m_objnum_array.Find(dwNum)) {
m_objnum_array.AddObjNum(dwNum);
CPDF_Object* pReferred =
- m_pDocument->GetIndirectObject(pRef->GetRefObjNum(), NULL);
+ m_pDocument->GetIndirectObject(pRef->GetRefObjNum(), nullptr);
if (pReferred) {
new_obj_array.Add(pReferred);
}
@@ -3644,7 +3642,7 @@ CPDF_Object* CPDF_DataAvail::ParseIndirectObjectAt(
return NULL;
}
CPDF_Object* pObj =
- m_syntaxParser.GetObject(pObjList, parser_objnum, gennum, 0);
+ m_syntaxParser.GetObject(pObjList, parser_objnum, gennum, nullptr, true);
m_syntaxParser.RestorePos(SavedPos);
return pObj;
}
@@ -3992,7 +3990,7 @@ FX_BOOL CPDF_DataAvail::CheckTrailer(IFX_DownloadHints* pHints) {
ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, FALSE));
m_syntaxParser.InitParser(file.get(), 0);
std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pTrailer(
- m_syntaxParser.GetObject(nullptr, 0, 0));
+ m_syntaxParser.GetObject(nullptr, 0, 0, nullptr, true));
if (!pTrailer) {
m_Pos += m_syntaxParser.SavePos();
pHints->AddSegment(m_Pos, iTrailerSize);