From 62664cee15230d6cbe08ed010721a4557b36dc22 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 5 Jan 2016 16:33:12 -0800 Subject: 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 . --- core/include/fpdfapi/fpdf_objects.h | 6 +-- core/include/fpdfapi/fpdf_parser.h | 12 ++--- core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp | 4 +- .../fpdfapi/fpdf_parser/fpdf_parser_document.cpp | 21 ++++---- core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp | 4 +- .../fpdfapi/fpdf_parser/fpdf_parser_objects.cpp | 26 ++++++---- .../src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp | 56 +++++++++++----------- 7 files changed, 69 insertions(+), 60 deletions(-) diff --git a/core/include/fpdfapi/fpdf_objects.h b/core/include/fpdfapi/fpdf_objects.h index e80801c507..a9a27c74a1 100644 --- a/core/include/fpdfapi/fpdf_objects.h +++ b/core/include/fpdfapi/fpdf_objects.h @@ -28,6 +28,7 @@ class CPDF_StreamAcc; class CPDF_StreamFilter; class CPDF_String; class IFX_FileRead; +struct PARSE_CONTEXT; #define PDFOBJ_INVALID 0 #define PDFOBJ_BOOLEAN 1 @@ -120,7 +121,7 @@ class CPDF_Object { ~CPDF_Object() {} void Destroy(); - static const int OBJECT_REF_MAX_DEPTH = 128; + static const int kObjectRefMaxDepth = 128; static int s_nCurRefDepth; FX_DWORD m_Type; FX_DWORD m_ObjNum; @@ -573,8 +574,7 @@ class CPDF_IndirectObjects { ~CPDF_IndirectObjects(); - CPDF_Object* GetIndirectObject(FX_DWORD objnum, - struct PARSE_CONTEXT* pContext = NULL); + CPDF_Object* GetIndirectObject(FX_DWORD objnum, PARSE_CONTEXT* pContext); int GetIndirectType(FX_DWORD objnum); diff --git a/core/include/fpdfapi/fpdf_parser.h b/core/include/fpdfapi/fpdf_parser.h index 4153b1d1f2..bcb35b0ad6 100644 --- a/core/include/fpdfapi/fpdf_parser.h +++ b/core/include/fpdfapi/fpdf_parser.h @@ -245,13 +245,13 @@ class CPDF_SyntaxParser { CPDF_Object* GetObject(CPDF_IndirectObjects* pObjList, FX_DWORD objnum, FX_DWORD gennum, - struct PARSE_CONTEXT* pContext = NULL, - FX_BOOL bDecrypt = TRUE); + PARSE_CONTEXT* pContext, + FX_BOOL bDecrypt); CPDF_Object* GetObjectByStrict(CPDF_IndirectObjects* pObjList, FX_DWORD objnum, FX_DWORD gennum, - struct PARSE_CONTEXT* pContext = NULL); + PARSE_CONTEXT* pContext); int GetDirectNum(); @@ -425,12 +425,12 @@ class CPDF_Parser { CPDF_Object* ParseIndirectObjectAt(CPDF_IndirectObjects* pObjList, FX_FILESIZE pos, FX_DWORD objnum, - struct PARSE_CONTEXT* pContext); + PARSE_CONTEXT* pContext); CPDF_Object* ParseIndirectObjectAtByStrict(CPDF_IndirectObjects* pObjList, FX_FILESIZE pos, FX_DWORD objnum, - struct PARSE_CONTEXT* pContext, + PARSE_CONTEXT* pContext, FX_FILESIZE* pResultPos); FX_DWORD StartAsynParse(IFX_FileRead* pFile, @@ -840,7 +840,7 @@ FX_DWORD RunLengthDecode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& dest_buf, FX_DWORD& dest_size); -FX_BOOL IsSignatureDict(const CPDF_Dictionary* pDict); +bool IsSignatureDict(const CPDF_Dictionary* pDict); class CPDF_NumberTree { public: diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp index 3fb5818543..2dc985413b 100644 --- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp +++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp @@ -1207,7 +1207,7 @@ int32_t CPDF_Creator::WriteDirectObj(FX_DWORD objnum, } m_Offset += 2; const CPDF_Dictionary* p = pObj->AsDictionary(); - FX_BOOL bSignDict = IsSignatureDict(p); + bool bSignDict = IsSignatureDict(p); FX_POSITION pos = p->GetStartPos(); while (pos) { FX_BOOL bSignValue = FALSE; @@ -1261,7 +1261,7 @@ int32_t CPDF_Creator::WriteOldIndirectObject(FX_DWORD objnum) { (m_pParser->m_V5Type[objnum] == 2) && m_pEncryptDict && !m_pXRefStream; if (m_pParser->m_bVersionUpdated || m_bSecurityChanged || bExistInMap || bObjStm) { - CPDF_Object* pObj = m_pDocument->GetIndirectObject(objnum); + CPDF_Object* pObj = m_pDocument->GetIndirectObject(objnum, nullptr); if (!pObj) { m_ObjectOffset[objnum] = 0; return 0; 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 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(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(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 visited; return CloneInternal(bDirect, &visited); @@ -1089,9 +1096,8 @@ CPDF_IndirectObjects::~CPDF_IndirectObjects() { static_cast(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>; -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> 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 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> 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> 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> 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); -- cgit v1.2.3