Chromium Code Reviews| Index: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp |
| diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp |
| index c705ea73576de248cec87e003635782a35a5ae99..3fd1c5e9bd72f116c39f4b403a0604387145520e 100644 |
| --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp |
| +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp |
| @@ -78,7 +78,7 @@ void CPDF_Parser::CloseParser(FX_BOOL bReParse) |
| } |
| ReleaseEncryptHandler(); |
| SetEncryptDictionary(NULL); |
| - if (m_bOwnFileRead && m_Syntax.m_pFileAccess != NULL) { |
| + if (m_bOwnFileRead && m_Syntax.m_pFileAccess) { |
| m_Syntax.m_pFileAccess->Release(); |
| m_Syntax.m_pFileAccess = NULL; |
| } |
| @@ -95,8 +95,10 @@ void CPDF_Parser::CloseParser(FX_BOOL bReParse) |
| m_V5Type.RemoveAll(); |
| m_ObjVersion.RemoveAll(); |
| FX_INT32 iLen = m_Trailers.GetSize(); |
| + CPDF_Dictionary* trailer; |
| for (FX_INT32 i = 0; i < iLen; ++i) { |
| - m_Trailers.GetAt(i)->Release(); |
| + if (trailer = m_Trailers.GetAt(i)) |
|
Nico
2014/06/28 01:01:07
Nit: If you want, you can write this as
if (CPD
Bo Xu
2014/06/28 01:26:27
I was wondering if this will initialize |trailer|
|
| + trailer->Release(); |
| } |
| m_Trailers.RemoveAll(); |
| if (m_pLinearized) { |
| @@ -1110,7 +1112,7 @@ FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE pos, FX_FILESIZE& prev, FX_BOOL |
| } |
| CPDF_Array* CPDF_Parser::GetIDArray() |
| { |
| - CPDF_Object* pID = m_pTrailer->GetElement(FX_BSTRC("ID")); |
| + CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("ID")) : NULL; |
| if (pID == NULL) { |
| return NULL; |
| } |
| @@ -1125,7 +1127,7 @@ CPDF_Array* CPDF_Parser::GetIDArray() |
| } |
| FX_DWORD CPDF_Parser::GetRootObjNum() |
| { |
| - CPDF_Reference* pRef = (CPDF_Reference*)m_pTrailer->GetElement(FX_BSTRC("Root")); |
| + CPDF_Reference* pRef = m_pTrailer ? (CPDF_Reference*)m_pTrailer->GetElement(FX_BSTRC("Root")) : NULL; |
| if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { |
| return 0; |
| } |
| @@ -1133,7 +1135,7 @@ FX_DWORD CPDF_Parser::GetRootObjNum() |
| } |
| FX_DWORD CPDF_Parser::GetInfoObjNum() |
| { |
| - CPDF_Reference* pRef = (CPDF_Reference*)m_pTrailer->GetElement(FX_BSTRC("Info")); |
| + CPDF_Reference* pRef = m_pTrailer ? (CPDF_Reference*)m_pTrailer->GetElement(FX_BSTRC("Info")) : NULL; |
| if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { |
| return 0; |
| } |
| @@ -1491,7 +1493,7 @@ FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, FX_DWORD offset |
| if (!m_pLinearized) { |
| return FALSE; |
| } |
| - if (m_pLinearized->GetDict()->GetElement(FX_BSTRC("Linearized"))) { |
| + if (m_pLinearized->GetDict() && m_pLinearized->GetDict()->GetElement(FX_BSTRC("Linearized"))) { |
| m_Syntax.GetNextWord(bIsNumber); |
| CPDF_Object *pLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L")); |
| if (!pLen) { |
| @@ -2150,7 +2152,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, FX_DWO |
| FX_BOOL bIsNumber; |
| CFX_ByteString key = GetNextWord(bIsNumber); |
| if (key.IsEmpty()) { |
| - pDict->Release(); |
| + if (pDict) |
| + pDict->Release(); |
| return NULL; |
| } |
| FX_FILESIZE SavedPos = m_Pos - key.GetLength(); |
| @@ -2206,7 +2209,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, FX_DWO |
| if (pStream) { |
| return pStream; |
| } |
| - pDict->Release(); |
| + if (pDict) |
| + pDict->Release(); |
| return NULL; |
| } else { |
| m_Pos = SavedPos; |
| @@ -2307,7 +2311,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(CPDF_IndirectObjects* pObjList |
| if (m_WordBuffer[0] == ']') { |
| return pArray; |
| } |
| - pArray->Release(); |
| + if (pArray) |
| + pArray->Release(); |
| return NULL; |
| } |
| pArray->Add(pObj); |
| @@ -2332,7 +2337,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(CPDF_IndirectObjects* pObjList |
| FX_FILESIZE SavedPos = m_Pos; |
| CFX_ByteString key = GetNextWord(bIsNumber); |
| if (key.IsEmpty()) { |
| - pDict->Release(); |
| + if (pDict) |
| + pDict->Release(); |
| return NULL; |
| } |
| if (key == FX_BSTRC(">>")) { |
| @@ -2348,7 +2354,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(CPDF_IndirectObjects* pObjList |
| key = PDF_NameDecode(key); |
| CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, level + 1); |
| if (pObj == NULL) { |
| - pDict->Release(); |
| + if (pDict) |
| + pDict->Release(); |
| FX_BYTE ch; |
| while (1) { |
| if (!GetNextChar(ch)) { |
| @@ -2380,7 +2387,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(CPDF_IndirectObjects* pObjList |
| if (pStream) { |
| return pStream; |
| } |
| - pDict->Release(); |
| + if (pDict) |
| + pDict->Release(); |
| return NULL; |
| } else { |
| m_Pos = SavedPos; |
| @@ -2835,7 +2843,7 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail(CFX_PtrArray& obj_array, FX_BOOL bParsePa |
| pObj = pObj->GetDict(); |
| case PDFOBJ_DICTIONARY: { |
| CPDF_Dictionary *pDict = pObj->GetDict(); |
| - if (pDict->GetString("Type") == "Page" && !bParsePage) { |
| + if (pDict && pDict->GetString("Type") == "Page" && !bParsePage) { |
| continue; |
| } |
| FX_POSITION pos = pDict->GetStartPos(); |
| @@ -3157,7 +3165,7 @@ FX_BOOL CPDF_DataAvail::CheckRoot(IFX_DownloadHints* pHints) |
| FX_BOOL CPDF_DataAvail::PreparePageItem() |
| { |
| CPDF_Dictionary *pRoot = m_pDocument->GetRoot(); |
| - CPDF_Reference* pRef = (CPDF_Reference*)pRoot->GetElement(FX_BSTRC("Pages")); |
| + CPDF_Reference* pRef = pRoot ? (CPDF_Reference*)pRoot->GetElement(FX_BSTRC("Pages")) : NULL; |
| if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { |
| m_docStatus = PDF_DATAAVAIL_ERROR; |
| return FALSE; |
| @@ -3270,7 +3278,8 @@ FX_BOOL CPDF_DataAvail::GetPageKids(CPDF_Parser *pParser, CPDF_Object *pPages) |
| m_docStatus = PDF_DATAAVAIL_ERROR; |
| return FALSE; |
| } |
| - CPDF_Object *pKids = pPages->GetDict()->GetElement(FX_BSTRC("Kids")); |
| + CPDF_Dictionary* pDict = pPages->GetDict(); |
| + CPDF_Object *pKids = pDict ? pDict->GetElement(FX_BSTRC("Kids")) : NULL; |
| if (!pKids) { |
| return TRUE; |
| } |
| @@ -3344,17 +3353,18 @@ FX_BOOL CPDF_DataAvail::CheckHeader(IFX_DownloadHints* pHints) |
| FX_BOOL CPDF_DataAvail::CheckFirstPage(IFX_DownloadHints *pHints) |
| { |
| FX_DWORD dwFirstPageEndOffset = 0; |
| - CPDF_Object *pEndOffSet = m_pLinearized->GetDict()->GetElement(FX_BSTRC("E")); |
| + CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
| + CPDF_Object *pEndOffSet = pDict ? pDict->GetElement(FX_BSTRC("E")) : NULL; |
| if (!pEndOffSet) { |
| m_docStatus = PDF_DATAAVAIL_ERROR; |
| return FALSE; |
| } |
| - CPDF_Object *pXRefOffset = m_pLinearized->GetDict()->GetElement(FX_BSTRC("T")); |
| + CPDF_Object *pXRefOffset = pDict ? pDict->GetElement(FX_BSTRC("T")) : NULL; |
| if (!pXRefOffset) { |
| m_docStatus = PDF_DATAAVAIL_ERROR; |
| return FALSE; |
| } |
| - CPDF_Object *pFileLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L")); |
| + CPDF_Object *pFileLen = pDict ? pDict->GetElement(FX_BSTRC("L")) : NULL; |
| if (!pFileLen) { |
| m_docStatus = PDF_DATAAVAIL_ERROR; |
| return FALSE; |
| @@ -3473,7 +3483,7 @@ FX_BOOL CPDF_DataAvail::IsLinearizedFile(FX_LPBYTE pData, FX_DWORD dwLen) |
| if (!m_pLinearized) { |
| return FALSE; |
| } |
| - if (m_pLinearized->GetDict()->GetElement(FX_BSTRC("Linearized"))) { |
| + if (m_pLinearized->GetDict() && m_pLinearized->GetDict()->GetElement(FX_BSTRC("Linearized"))) { |
| CPDF_Object *pLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L")); |
| if (!pLen) { |
| return FALSE; |
| @@ -3548,7 +3558,8 @@ FX_DWORD CPDF_DataAvail::CheckCrossRefStream(IFX_DownloadHints* pHints, FX_FILES |
| m_Pos += m_parser.m_Syntax.SavePos(); |
| return 0; |
| } |
| - CPDF_Object *pName = pObj->GetDict()->GetElement(FX_BSTRC("Type")); |
| + CPDF_Dictionary* pDict = pObj->GetDict(); |
| + CPDF_Object *pName = pDict ? pDict->GetElement(FX_BSTRC("Type")) : NULL; |
| if (pName && pName->GetType() == PDFOBJ_NAME) { |
| if (pName->GetString() == FX_BSTRC("XRef")) { |
| m_Pos += m_parser.m_Syntax.SavePos(); |
| @@ -3908,10 +3919,11 @@ FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo, CPDF_PageNode *pP |
| return FALSE; |
| } |
| pPageNode->m_dwPageNo = dwPageNo; |
| - CFX_ByteString type = pPage->GetDict()->GetString(FX_BSTRC("Type")); |
| + CPDF_Dictionary* pDict = pPage->GetDict(); |
| + CFX_ByteString type = pDict ? pDict->GetString(FX_BSTRC("Type")) : CFX_ByteString(); |
| if (type == FX_BSTRC("Pages")) { |
| pPageNode->m_type = PDF_PAGENODE_PAGES; |
| - CPDF_Object *pKids = pPage->GetDict()->GetElement(FX_BSTRC("Kids")); |
| + CPDF_Object *pKids = pDict->GetElement(FX_BSTRC("Kids")); |
| if (!pKids) { |
| m_docStatus = PDF_DATAAVAIL_PAGE; |
| return TRUE; |