From 287e11a213d3197ac3e321acf294d903b271c269 Mon Sep 17 00:00:00 2001 From: Bo Xu Date: Mon, 30 Jun 2014 09:49:21 -0700 Subject: Remove "this==NULL" and adjust corresponding callers BUG= R=thakis@chromium.org Review URL: https://codereview.chromium.org/361553002 --- core/include/fpdfapi/fpdf_objects.h | 2 +- core/include/fpdfapi/fpdf_resource.h | 2 +- core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp | 8 +- core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp | 7 +- core/src/fpdfapi/fpdf_font/fpdf_font.cpp | 10 +- core/src/fpdfapi/fpdf_page/fpdf_page.cpp | 5 +- core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp | 15 +- core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp | 2 +- core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp | 2 +- .../fpdfapi/fpdf_page/fpdf_page_graph_state.cpp | 8 +- core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 21 +- .../src/fpdfapi/fpdf_page/fpdf_page_parser_new.cpp | 4 +- .../src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp | 4 +- core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp | 2 +- .../src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp | 8 +- .../fpdfapi/fpdf_parser/fpdf_parser_document.cpp | 8 +- .../fpdfapi/fpdf_parser/fpdf_parser_encrypt.cpp | 8 +- core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp | 8 +- .../fpdfapi/fpdf_parser/fpdf_parser_filters.cpp | 4 +- .../fpdfapi/fpdf_parser/fpdf_parser_objects.cpp | 251 ++++++++------------- .../src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp | 55 +++-- core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp | 6 +- .../fpdfapi/fpdf_render/fpdf_render_loadimage.cpp | 2 +- core/src/fpdfdoc/doc_annot.cpp | 5 +- core/src/fpdfdoc/doc_ap.cpp | 30 +-- core/src/fpdfdoc/doc_basic.cpp | 5 +- core/src/fpdfdoc/doc_formfield.cpp | 17 +- core/src/fpdftext/fpdf_text_int.cpp | 2 +- core/src/fxcrt/fx_xml_parser.cpp | 2 +- fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp | 8 +- fpdfsdk/src/fpdf_ext.cpp | 6 +- fpdfsdk/src/fpdf_transformpage.cpp | 8 +- fpdfsdk/src/fpdfeditpage.cpp | 16 +- fpdfsdk/src/fpdfppo.cpp | 5 +- fpdfsdk/src/pdfwindow/PWL_Icon.cpp | 2 +- 35 files changed, 269 insertions(+), 279 deletions(-) diff --git a/core/include/fpdfapi/fpdf_objects.h b/core/include/fpdfapi/fpdf_objects.h index 622f39d35f..a41ff087ca 100644 --- a/core/include/fpdfapi/fpdf_objects.h +++ b/core/include/fpdfapi/fpdf_objects.h @@ -620,7 +620,7 @@ public: CPDF_Dictionary* GetDict() const { - return m_pStream->GetDict(); + return m_pStream? m_pStream->GetDict() : NULL; } FX_LPCBYTE GetData() const; diff --git a/core/include/fpdfapi/fpdf_resource.h b/core/include/fpdfapi/fpdf_resource.h index 49e7148ee6..7e9e412325 100644 --- a/core/include/fpdfapi/fpdf_resource.h +++ b/core/include/fpdfapi/fpdf_resource.h @@ -882,7 +882,7 @@ public: CPDF_Dictionary* GetDict() const { - return m_pStream->GetDict(); + return m_pStream? m_pStream->GetDict(): NULL; } CPDF_Dictionary* GetOC() const diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp index 243c23fabf..e33a99ba63 100644 --- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp +++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp @@ -48,7 +48,7 @@ void CPDF_PageContentGenerate::GenerateContent() } ProcessImage(buf, (CPDF_ImageObject*)pPageObj); } - CPDF_Object* pContent = pPageDict->GetElementValue("Contents"); + CPDF_Object* pContent = pPageDict ? pPageDict->GetElementValue("Contents") : NULL; if (pContent != NULL) { pPageDict->RemoveAt("Contents"); } @@ -94,7 +94,8 @@ void CPDF_PageContentGenerate::ProcessImage(CFX_ByteTextBuf& buf, CPDF_ImageObje FX_DWORD dwSavedObjNum = pStream->GetObjNum(); CFX_ByteString name = RealizeResource(pStream, "XObject"); if (dwSavedObjNum == 0) { - pImageObj->m_pImage->Release(); + if (pImageObj->m_pImage) + pImageObj->m_pImage->Release(); pImageObj->m_pImage = m_pDocument->GetPageData()->GetImage(pStream); } buf << "/" << PDF_NameEncode(name) << " Do Q\n"; @@ -119,7 +120,8 @@ void CPDF_PageContentGenerate::ProcessForm(CFX_ByteTextBuf& buf, FX_LPCBYTE data } void CPDF_PageContentGenerate::TransformContent(CFX_Matrix& matrix) { - CPDF_Object* pContent = m_pPage->m_pFormDict->GetElementValue("Contents"); + CPDF_Dictionary* pDict = m_pPage->m_pFormDict; + CPDF_Object* pContent = pDict ? pDict->GetElementValue("Contents") : NULL; if (!pContent) { return; } diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp index bdbcccdf06..9eec7aa4a8 100644 --- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp +++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp @@ -334,7 +334,7 @@ void CPDF_FlateEncoder::CloneDict() FX_BOOL CPDF_FlateEncoder::Initialize(CPDF_Stream* pStream, FX_BOOL bFlateEncode) { m_Acc.LoadAllData(pStream, TRUE); - if (pStream->GetDict()->KeyExist("Filter") || !bFlateEncode) { + if ((pStream && pStream->GetDict() && pStream->GetDict()->KeyExist("Filter")) || !bFlateEncode) { if (pStream->GetDict()->KeyExist("Filter") && !bFlateEncode) { CPDF_StreamAcc destAcc; destAcc.LoadAllData(pStream); @@ -1482,7 +1482,8 @@ FX_INT32 CPDF_Creator::WriteDoc_Stage1(IFX_Pause *pPause) if (m_bSecurityChanged && (m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0) { m_dwFlags &= ~FPDFCREATE_INCREMENTAL; } - m_pMetadata = m_pDocument->GetRoot()->GetElementValue(FX_BSTRC("Metadata")); + CPDF_Dictionary* pDict = m_pDocument->GetRoot(); + m_pMetadata = pDict ? pDict->GetElementValue(FX_BSTRC("Metadata")) : NULL; if (m_dwFlags & FPDFCREATE_OBJECTSTREAM) { m_pXRefStream = FX_NEW CPDF_XRefStream; m_pXRefStream->Start(); @@ -2032,7 +2033,7 @@ void CPDF_Creator::InitID(FX_BOOL bDefault ) if (!m_pIDArray) { FX_LPDWORD pBuffer = NULL; m_pIDArray = CPDF_Array::Create(); - CPDF_Object* pID1 = pOldIDArray->GetElement(0); + CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetElement(0) : NULL; if (pID1) { m_pIDArray->Add(pID1->Clone()); } else { diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp index 72b8adbe20..b7ca5b1b7d 100644 --- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp +++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp @@ -78,7 +78,9 @@ void CPDF_FontGlobals::Clear(void* key) CFX_StockFontArray* pStockFonts = (CFX_StockFontArray*)value; for (int i = 0; i < 14; i ++) { if (pStockFonts->m_pStockFonts[i]) { - pStockFonts->m_pStockFonts[i]->GetFontDict()->Release(); + CPDF_Dictionary* pFontDict = pStockFonts->m_pStockFonts[i]->GetFontDict(); + if (pFontDict) + pFontDict->Release(); delete pStockFonts->m_pStockFonts[i]; } } @@ -97,7 +99,9 @@ void CPDF_FontGlobals::ClearAll() CFX_StockFontArray* pStockFonts = (CFX_StockFontArray*)value; for (int i = 0; i < 14; i ++) { if (pStockFonts->m_pStockFonts[i]) { - pStockFonts->m_pStockFonts[i]->GetFontDict()->Release(); + CPDF_Dictionary* pFontDict = pStockFonts->m_pStockFonts[i]->GetFontDict(); + if (pFontDict) + pFontDict->Release(); delete pStockFonts->m_pStockFonts[i]; } } @@ -1698,7 +1702,7 @@ CPDF_Type3Char* CPDF_Type3Font::LoadChar(FX_DWORD charcode, int level) if (name == NULL) { return NULL; } - CPDF_Stream* pStream = (CPDF_Stream*)m_pCharProcs->GetElementValue(name); + CPDF_Stream* pStream = (CPDF_Stream*)(m_pCharProcs ? m_pCharProcs->GetElementValue(name) : NULL); if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM) { return NULL; } diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp index 3cfb93e4bc..500fe4a57f 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp @@ -841,7 +841,8 @@ void CPDF_Page::Load(CPDF_Document* pDocument, CPDF_Dictionary* pPageDict, FX_BO m_pPageResources = m_pResources = NULL; return; } - m_pResources = GetPageAttr(FX_BSTRC("Resources"))->GetDict(); + CPDF_Object* pageAttr = GetPageAttr(FX_BSTRC("Resources")); + m_pResources = pageAttr ? pageAttr->GetDict() : NULL; m_pPageResources = m_pResources; CPDF_Object* pRotate = GetPageAttr(FX_BSTRC("Rotate")); int rotate = 0; @@ -946,7 +947,7 @@ CPDF_Form::CPDF_Form(CPDF_Document* pDoc, CPDF_Dictionary* pPageResources, CPDF_ { m_pDocument = pDoc; m_pFormStream = pFormStream; - m_pFormDict = pFormStream->GetDict(); + m_pFormDict = pFormStream ? pFormStream->GetDict() : NULL; m_pResources = m_pFormDict->GetDict(FX_BSTRC("Resources")); m_pPageResources = pPageResources; if (m_pResources == NULL) { diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp index c13395c7ce..ff44c591c7 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp @@ -281,7 +281,7 @@ FX_BOOL CPDF_CalGray::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) CPDF_Array* pParam = pDict->GetArray(FX_BSTRC("WhitePoint")); int i; for (i = 0; i < 3; i ++) { - m_WhitePoint[i] = pParam->GetNumber(i); + m_WhitePoint[i] = pParam ? pParam->GetNumber(i) : 0; } pParam = pDict->GetArray(FX_BSTRC("BlackPoint")); for (i = 0; i < 3; i ++) { @@ -340,7 +340,7 @@ FX_BOOL CPDF_CalRGB::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) CPDF_Array* pParam = pDict->GetArray(FX_BSTRC("WhitePoint")); int i; for (i = 0; i < 3; i ++) { - m_WhitePoint[i] = pParam->GetNumber(i); + m_WhitePoint[i] = pParam ? pParam->GetNumber(i) : 0; } pParam = pDict->GetArray(FX_BSTRC("BlackPoint")); for (i = 0; i < 3; i ++) { @@ -438,7 +438,7 @@ FX_BOOL CPDF_LabCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) CPDF_Array* pParam = pDict->GetArray(FX_BSTRC("WhitePoint")); int i; for (i = 0; i < 3; i ++) { - m_WhitePoint[i] = pParam->GetNumber(i); + m_WhitePoint[i] = pParam ? pParam->GetNumber(i) : 0; } pParam = pDict->GetArray(FX_BSTRC("BlackPoint")); for (i = 0; i < 3; i ++) { @@ -580,11 +580,12 @@ FX_BOOL CPDF_ICCBasedCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) if (pStream == NULL) { return FALSE; } - m_nComponents = pStream->GetDict()->GetInteger(FX_BSTRC("N")); + CPDF_Dictionary* pDict = pStream->GetDict(); + m_nComponents = pDict ? pDict->GetInteger(FX_BSTRC("N")) : 0; if (m_nComponents < 0 || m_nComponents > (1 << 16)) { return FALSE; } - CPDF_Array* pRanges = pStream->GetDict()->GetArray(FX_BSTRC("Range")); + CPDF_Array* pRanges = pDict->GetArray(FX_BSTRC("Range")); m_pRanges = FX_Alloc(FX_FLOAT, m_nComponents * 2); for (int i = 0; i < m_nComponents * 2; i ++) { if (pRanges) { @@ -600,7 +601,7 @@ FX_BOOL CPDF_ICCBasedCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) return FALSE; } if (m_pProfile->m_pTransform == NULL) { - CPDF_Object* pAlterCSObj = pStream->GetDict()->GetElementValue(FX_BSTRC("Alternate")); + CPDF_Object* pAlterCSObj = pDict ? pDict->GetElementValue(FX_BSTRC("Alternate")) : NULL; if (pAlterCSObj) { CPDF_ColorSpace* alter_cs = CPDF_ColorSpace::Load(pDoc, pAlterCSObj); if (alter_cs) { @@ -1079,7 +1080,7 @@ CPDF_ColorSpace* CPDF_ColorSpace::Load(CPDF_Document* pDoc, CPDF_Object* pObj) while (pos) { CFX_ByteString bsKey; CPDF_Object *pValue = pDict->GetNextElement(pos, bsKey); - if (pValue->GetType() == PDFOBJ_NAME) { + if (pValue && pValue->GetType() == PDFOBJ_NAME) { pRet = _CSFromName(pValue->GetString()); } if (pRet) { diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp index a9d2c4d695..c152b223c9 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp @@ -485,7 +485,7 @@ CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, FX_BOOL bSh if (bShading) { pPattern = FX_NEW CPDF_ShadingPattern(m_pPDFDoc, pPatternObj, bShading, matrix); } else { - CPDF_Dictionary* pDict = pPatternObj->GetDict(); + CPDF_Dictionary* pDict = pPatternObj ? pPatternObj->GetDict() : NULL; if (pDict) { int type = pDict->GetInteger(FX_BSTRC("PatternType")); if (type == 1) { diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp index 5b178f955e..af22c5649e 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp @@ -486,7 +486,7 @@ FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) int i; FX_DWORD nTotalSamples = 1; for (i = 0; i < m_nInputs; i ++) { - m_pEncodeInfo[i].sizes = pSize->GetInteger(i); + m_pEncodeInfo[i].sizes = pSize ? pSize->GetInteger(i) : 0; if (!pSize && i == 0) { m_pEncodeInfo[i].sizes = pDict->GetInteger(FX_BSTRC("Size")); } diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp index f53a5b23a4..628fb3da99 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp @@ -194,7 +194,8 @@ void CPDF_ClipPath::AppendTexts(CPDF_TextObject** pTexts, int count) CPDF_ClipPathData* pData = GetModify(); if (pData->m_TextCount + count > FPDF_CLIPPATH_MAX_TEXTS) { for (int i = 0; i < count; i ++) { - pTexts[i]->Release(); + if (pTexts[i]) + pTexts[i]->Release(); } return; } @@ -481,7 +482,8 @@ void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, CPDF_StreamContentParser FX_POSITION pos = pGS->GetStartPos(); while (pos) { CFX_ByteString key_str; - CPDF_Object* pObject = pGS->GetNextElement(pos, key_str)->GetDirect(); + CPDF_Object* pElement = pGS->GetNextElement(pos, key_str); + CPDF_Object* pObject = pElement ? pElement->GetDirect() : NULL; if (pObject == NULL) { continue; } @@ -625,7 +627,7 @@ CPDF_ContentMarkItem::CPDF_ContentMarkItem(const CPDF_ContentMarkItem& src) } CPDF_ContentMarkItem::~CPDF_ContentMarkItem() { - if (m_ParamType == DirectDict) { + if (m_ParamType == DirectDict && m_pParam) { ((CPDF_Dictionary*)m_pParam)->Release(); } } diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp index ff670965ec..5e8c1b5ec3 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -140,7 +140,8 @@ int CPDF_StreamContentParser::GetNextParamPos() m_ParamStartPos = 0; } if (m_ParamBuf1[m_ParamStartPos].m_Type == 0) { - m_ParamBuf1[m_ParamStartPos].m_pObject->Release(); + if (CPDF_Object* pObject = m_ParamBuf1[m_ParamStartPos].m_pObject) + pObject->Release(); } return m_ParamStartPos; } @@ -187,7 +188,8 @@ void CPDF_StreamContentParser::ClearAllParams() FX_DWORD index = m_ParamStartPos; for (FX_DWORD i = 0; i < m_ParamCount; i ++) { if (m_ParamBuf1[index].m_Type == 0) { - m_ParamBuf1[index].m_pObject->Release(); + if (CPDF_Object* pObject = m_ParamBuf1[index].m_pObject) + pObject->Release(); } index ++; if (index == PARAM_BUF_SIZE) { @@ -238,7 +240,7 @@ CFX_ByteString CPDF_StreamContentParser::GetString(FX_DWORD index) if (param.m_Type == PDFOBJ_NAME) { return CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len); } - if (param.m_Type == 0) { + if (param.m_Type == 0 && param.m_pObject) { return param.m_pObject->GetString(); } return CFX_ByteString(); @@ -256,7 +258,7 @@ FX_FLOAT CPDF_StreamContentParser::GetNumber(FX_DWORD index) if (param.m_Type == PDFOBJ_NUMBER) { return param.m_Number.m_bInteger ? (FX_FLOAT)param.m_Number.m_Integer : param.m_Number.m_Float; } - if (param.m_Type == 0) { + if (param.m_Type == 0 && param.m_pObject) { return param.m_pObject->GetNumber(); } return 0; @@ -653,7 +655,7 @@ void CPDF_StreamContentParser::Handle_SetDash() if (m_Options.m_bTextOnly) { return; } - CPDF_Array* pArray = GetObject(1)->GetArray(); + CPDF_Array* pArray = GetObject(1) ? GetObject(1)->GetArray() : NULL; if (pArray == NULL) { return; } @@ -728,7 +730,7 @@ void CPDF_StreamContentParser::Handle_ExecuteXObject() m_bResourceMissing = TRUE; return; } - CFX_ByteStringC type = pXObject->GetDict()->GetConstString(FX_BSTRC("Subtype")); + CFX_ByteStringC type = pXObject->GetDict() ? pXObject->GetDict()->GetConstString(FX_BSTRC("Subtype")) : CFX_ByteStringC(); if (type == FX_BSTRC("Image")) { if (m_Options.m_bTextOnly) { return; @@ -1425,7 +1427,7 @@ void CPDF_StreamContentParser::Handle_ShowText() } void CPDF_StreamContentParser::Handle_ShowText_Positioning() { - CPDF_Array* pArray = GetObject(0)->GetArray(); + CPDF_Array* pArray = GetObject(0) ? GetObject(0)->GetArray() : NULL; if (pArray == NULL) { return; } @@ -1457,10 +1459,11 @@ void CPDF_StreamContentParser::Handle_ShowText_Positioning() pStrs[iSegment] = str; pKerning[iSegment ++] = 0; } else { + FX_FLOAT num = pObj ? pObj->GetNumber() : 0; if (iSegment == 0) { - fInitKerning += pObj->GetNumber(); + fInitKerning += num; } else { - pKerning[iSegment - 1] += pObj->GetNumber(); + pKerning[iSegment - 1] += num; } } } diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_new.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_new.cpp index 5442f9b4ec..24ec7436aa 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_new.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_new.cpp @@ -498,9 +498,9 @@ void CPDF_StreamContentParser::EndImageDict() m_bSameLastDict = TRUE; } m_ImageSrcBuf.Clear(); - if (m_pLastCloneImageDict) { + if (m_pLastCloneImageDict) m_pLastCloneImageDict->Release(); - } + m_pLastCloneImageDict = (CPDF_Dictionary*)m_pLastImageDict->Clone(); if (m_pLastCloneImageDict->KeyExist(FX_BSTRC("Filter"))) { m_WordState = 10; diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp index 8cd9f2bdb5..fe5e59c698 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp @@ -91,7 +91,7 @@ void CPDF_StreamContentParser::Handle_BeginImage() CPDF_Object* pObj = m_pSyntax->ReadNextObject(); if (!key.IsEmpty()) { pDict->SetAt(key, pObj, m_pDocument); - } else { + } else if (pObj) { pObj->Release(); } } @@ -1064,7 +1064,7 @@ void CPDF_ContentParser::Continue(IFX_Pause* pPause) } else { CPDF_Array* pContent = m_pObjects->m_pFormDict->GetArray(FX_BSTRC("Contents")); m_pStreamArray[m_CurrentOffset] = FX_NEW CPDF_StreamAcc; - CPDF_Stream* pStreamObj = (CPDF_Stream*)pContent->GetElementValue(m_CurrentOffset); + CPDF_Stream* pStreamObj = (CPDF_Stream*)(pContent ? pContent->GetElementValue(m_CurrentOffset) : NULL); m_pStreamArray[m_CurrentOffset]->LoadAllData(pStreamObj, FALSE); m_CurrentOffset ++; } diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp index 6c6c095980..8cb6dc77dc 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp @@ -97,7 +97,7 @@ FX_BOOL CPDF_ShadingPattern::Load() if (m_ShadingType != 0) { return TRUE; } - CPDF_Dictionary* pShadingDict = m_pShadingObj->GetDict(); + CPDF_Dictionary* pShadingDict = m_pShadingObj ? m_pShadingObj->GetDict() : NULL; if (pShadingDict == NULL) { return FALSE; } diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp index 6b2483eda7..5854d71344 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp @@ -45,7 +45,7 @@ FX_DWORD _A85Decode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_b return (FX_DWORD) - 1; } int state = 0; - FX_UINT32 res = 0; + FX_UINT32 res = 0; pos = dest_size = 0; while (pos < src_size) { FX_BYTE ch = src_buf[pos++]; @@ -281,11 +281,11 @@ FX_BOOL PDF_DataDecode(FX_LPCBYTE src_buf, FX_DWORD src_size, const CPDF_Diction CPDF_Dictionary*& pImageParms, FX_DWORD last_estimated_size, FX_BOOL bImageAcc) { - CPDF_Object* pDecoder = pDict->GetElementValue(FX_BSTRC("Filter")); + CPDF_Object* pDecoder = pDict ? pDict->GetElementValue(FX_BSTRC("Filter")) : NULL; if (pDecoder == NULL || (pDecoder->GetType() != PDFOBJ_ARRAY && pDecoder->GetType() != PDFOBJ_NAME)) { return FALSE; } - CPDF_Object* pParams = pDict->GetElementValue(FX_BSTRC("DecodeParms")); + CPDF_Object* pParams = pDict ? pDict->GetElementValue(FX_BSTRC("DecodeParms")) : NULL; CFX_ByteStringArray DecoderList; CFX_PtrArray ParamList; if (pDecoder->GetType() == PDFOBJ_ARRAY) { @@ -304,7 +304,7 @@ FX_BOOL PDF_DataDecode(FX_LPCBYTE src_buf, FX_DWORD src_size, const CPDF_Diction } } else { DecoderList.Add(pDecoder->GetConstString()); - ParamList.Add(pParams->GetDict()); + ParamList.Add(pParams ? pParams->GetDict() : NULL); } FX_LPBYTE last_buf = (FX_LPBYTE)src_buf; FX_DWORD last_size = src_size; diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp index a4982040bf..cd100a80cc 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp @@ -61,11 +61,13 @@ void CPDF_Document::LoadAsynDoc(CPDF_Dictionary *pLinearized) { m_bLinearized = TRUE; m_LastObjNum = m_pParser->GetLastObjNum(); - m_pRootDict = GetIndirectObject(m_pParser->GetRootObjNum())->GetDict(); + CPDF_Object* indirectObj = GetIndirectObject(m_pParser->GetRootObjNum()); + m_pRootDict = indirectObj ? indirectObj->GetDict() : NULL; if (m_pRootDict == NULL) { return; } - m_pInfoDict = GetIndirectObject(m_pParser->GetInfoObjNum())->GetDict(); + indirectObj = GetIndirectObject(m_pParser->GetInfoObjNum()); + m_pInfoDict = indirectObj ? indirectObj->GetDict() : NULL; CPDF_Array* pIDArray = m_pParser->GetIDArray(); if (pIDArray) { m_ID1 = pIDArray->GetString(0); @@ -336,7 +338,7 @@ FX_BOOL CPDF_Document::IsContentUsedElsewhere(FX_DWORD objnum, CPDF_Dictionary* if (pPageDict == pThisPageDict) { continue; } - CPDF_Object* pContents = pPageDict->GetElement(FX_BSTRC("Contents")); + CPDF_Object* pContents = pPageDict ? pPageDict->GetElement(FX_BSTRC("Contents")) : NULL; if (pContents == NULL) { continue; } diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_encrypt.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_encrypt.cpp index fadcd38b1b..e09bbbbb2e 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_encrypt.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_encrypt.cpp @@ -292,11 +292,11 @@ void Revision6_Hash(FX_LPCBYTE password, FX_DWORD size, FX_LPCBYTE salt, FX_LPCB FX_BOOL CPDF_StandardSecurityHandler::AES256_CheckPassword(FX_LPCBYTE password, FX_DWORD size, FX_BOOL bOwner, FX_LPBYTE key) { - CFX_ByteString okey = m_pEncryptDict->GetString(FX_BSTRC("O")); + CFX_ByteString okey = m_pEncryptDict ? m_pEncryptDict->GetString(FX_BSTRC("O")) : CFX_ByteString(); if (okey.GetLength() < 48) { return FALSE; } - CFX_ByteString ukey = m_pEncryptDict->GetString(FX_BSTRC("U")); + CFX_ByteString ukey = m_pEncryptDict ? m_pEncryptDict->GetString(FX_BSTRC("U")) : CFX_ByteString(); if (ukey.GetLength() < 48) { return FALSE; } @@ -331,7 +331,7 @@ FX_BOOL CPDF_StandardSecurityHandler::AES256_CheckPassword(FX_LPCBYTE password, } CRYPT_SHA256Finish(sha, digest); } - CFX_ByteString ekey = m_pEncryptDict->GetString(bOwner ? FX_BSTRC("OE") : FX_BSTRC("UE")); + CFX_ByteString ekey = m_pEncryptDict ? m_pEncryptDict->GetString(bOwner ? FX_BSTRC("OE") : FX_BSTRC("UE")) : CFX_ByteString(); if (ekey.GetLength() < 32) { return FALSE; } @@ -391,7 +391,7 @@ FX_BOOL CPDF_StandardSecurityHandler::CheckUserPassword(FX_LPCBYTE password, FX_ { CalcEncryptKey(m_pEncryptDict, password, pass_size, key, key_len, bIgnoreEncryptMeta, m_pParser->GetIDArray()); - CFX_ByteString ukey = m_pEncryptDict->GetString(FX_BSTRC("U")); + CFX_ByteString ukey = m_pEncryptDict ? m_pEncryptDict->GetString(FX_BSTRC("U")) : CFX_ByteString(); if (ukey.GetLength() < 16) { return FALSE; } diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp index 36cc9db754..dd4eeddc17 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp @@ -111,7 +111,8 @@ FX_BOOL CFDF_Document::WriteBuf(CFX_ByteTextBuf& buf) const } CFX_WideString CFDF_Document::GetWin32Path() const { - CPDF_Object* pFileSpec = m_pRootDict->GetDict(FX_BSTRC("FDF"))->GetElementValue(FX_BSTRC("F")); + CPDF_Dictionary* pDict = m_pRootDict ? m_pRootDict->GetDict(FX_BSTRC("FDF")) : NULL; + CPDF_Object* pFileSpec = pDict ? pDict->GetElementValue(FX_BSTRC("F")) : NULL; if (pFileSpec == NULL) { return CFX_WideString(); } @@ -203,7 +204,10 @@ CFX_WideString FPDF_FileSpec_GetWin32Path(const CPDF_Object* pFileSpec) if (wsFileName.IsEmpty() && pDict->KeyExist(FX_BSTRC("DOS"))) { wsFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("DOS"))); } - } else { + } + else if (!pFileSpec) + wsFileName = CFX_WideString(); + else { wsFileName = CFX_WideString::FromLocal(pFileSpec->GetString()); } if (wsFileName[0] != '/') { diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_filters.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_filters.cpp index 1e4e1570df..610fb39781 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_filters.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_filters.cpp @@ -76,11 +76,11 @@ CFX_DataFilter* FPDF_CreateFilter(FX_BSTR name, const CPDF_Dictionary* pParam, i case FXBSTR_ID('L', 'Z', 'W', 0): { CFX_DataFilter* pFilter; if (id == FXBSTR_ID('L', 'Z', 'W', 'D') || id == FXBSTR_ID('L', 'Z', 'W', 0)) { - pFilter = FX_NEW CPDF_LzwFilter(pParam->GetInteger("EarlyChange", 1)); + pFilter = FX_NEW CPDF_LzwFilter(pParam ? pParam->GetInteger("EarlyChange", 1) : 1); } else { pFilter = FX_NEW CPDF_FlateFilter; } - if (pParam->GetInteger("Predictor", 1) > 1) { + if ((pParam ? pParam->GetInteger("Predictor", 1) : 1) > 1) { CFX_DataFilter* pPredictor = FX_NEW CPDF_PredictorFilter(pParam->GetInteger(FX_BSTRC("Predictor"), 1), pParam->GetInteger(FX_BSTRC("Colors"), 1), pParam->GetInteger(FX_BSTRC("BitsPerComponent"), 8), pParam->GetInteger(FX_BSTRC("Columns"), 1)); diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp index bd8b157bfa..6c93bcb39f 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp @@ -7,9 +7,6 @@ #include "../../../include/fpdfapi/fpdf_parser.h" void CPDF_Object::Release() { - if (this == NULL) { - return; - } if (m_ObjNum) { return; } @@ -39,9 +36,6 @@ void CPDF_Object::Destroy() } CFX_ByteString CPDF_Object::GetString() const { - if (this == NULL) { - return CFX_ByteString(); - } switch (m_Type) { case PDFOBJ_BOOLEAN: return ((CPDF_Boolean*)this)->m_bValue ? "true" : "false"; @@ -67,9 +61,6 @@ CFX_ByteString CPDF_Object::GetString() const } CFX_ByteStringC CPDF_Object::GetConstString() const { - if (this == NULL) { - return CFX_ByteStringC(); - } switch (m_Type) { case PDFOBJ_STRING: return CFX_ByteStringC((FX_LPCBYTE)((CPDF_String*)this)->m_String, ((CPDF_String*)this)->m_String.GetLength()); @@ -91,9 +82,6 @@ CFX_ByteStringC CPDF_Object::GetConstString() const } FX_FLOAT CPDF_Object::GetNumber() const { - if (this == NULL) { - return 0; - } switch (m_Type) { case PDFOBJ_NUMBER: return ((CPDF_Number*)this)->GetNumber(); @@ -117,9 +105,6 @@ FX_FLOAT CPDF_Object::GetNumber16() const } int CPDF_Object::GetInteger() const { - if (this == NULL) { - return 0; - } switch (m_Type) { case PDFOBJ_BOOLEAN: return ((CPDF_Boolean*)this)->m_bValue; @@ -143,9 +128,6 @@ int CPDF_Object::GetInteger() const } CPDF_Dictionary* CPDF_Object::GetDict() const { - if (this == NULL) { - return NULL; - } switch (m_Type) { case PDFOBJ_DICTIONARY: return (CPDF_Dictionary*)this; @@ -167,13 +149,10 @@ CPDF_Dictionary* CPDF_Object::GetDict() const } CPDF_Array* CPDF_Object::GetArray() const { - if (this == NULL) { - return NULL; - } - if (m_Type == PDFOBJ_ARRAY) { + if (m_Type == PDFOBJ_ARRAY) return (CPDF_Array*)this; - } - return NULL; + else + return NULL; } void CPDF_Object::SetString(const CFX_ByteString& str) { @@ -207,11 +186,11 @@ FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const if (this == pOther) { return TRUE; } - if (this == NULL || pOther == NULL) { + if (pOther == NULL) { return FALSE; } if (pOther->m_Type != m_Type) { - if (m_Type == PDFOBJ_REFERENCE) { + if (m_Type == PDFOBJ_REFERENCE && GetDirect()) { return GetDirect()->IsIdentical(pOther); } else if (pOther->m_Type == PDFOBJ_REFERENCE) { return IsIdentical(pOther->GetDirect()); @@ -242,9 +221,6 @@ FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const } CPDF_Object* CPDF_Object::GetDirect() const { - if (this == NULL) { - return NULL; - } if (m_Type != PDFOBJ_REFERENCE) { return (CPDF_Object*)this; } @@ -261,9 +237,6 @@ CPDF_Object* CPDF_Object::Clone(FX_BOOL bDirect) const } CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, CFX_MapPtrToPtr* visited) const { - if (this == NULL) { - return NULL; - } switch (m_Type) { case PDFOBJ_BOOLEAN: return FX_NEW CPDF_Boolean(((CPDF_Boolean*)this)->m_bValue); @@ -303,7 +276,11 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, CFX_MapPtrToPtr* visite CPDF_StreamAcc acc; acc.LoadAllData(pThis, TRUE); FX_DWORD streamSize = acc.GetSize(); - CPDF_Stream* pObj = FX_NEW CPDF_Stream(acc.DetachData(), streamSize, (CPDF_Dictionary*)((CPDF_Object*)pThis->GetDict())->CloneInternal(bDirect, visited)); + CPDF_Stream* pObj; + if (pThis->GetDict()) + pObj = FX_NEW CPDF_Stream(acc.DetachData(), streamSize, (CPDF_Dictionary*)((CPDF_Object*)pThis->GetDict())->CloneInternal(bDirect, visited)); + else + pObj = FX_NEW CPDF_Stream(acc.DetachData(), streamSize, NULL); return pObj; } case PDFOBJ_REFERENCE: { @@ -311,7 +288,11 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, CFX_MapPtrToPtr* visite FX_DWORD obj_num = pRef->m_RefObjNum; if (bDirect && !visited->GetValueAt((void*)(FX_UINTPTR)obj_num)) { visited->SetAt((void*)(FX_UINTPTR)obj_num, (void*)1); - CPDF_Object* ret = pRef->GetDirect()->CloneInternal(TRUE, visited); + CPDF_Object* ret; + if (pRef->GetDirect()) + ret = pRef->GetDirect()->CloneInternal(TRUE, visited); + else + ret = NULL; return ret; } else { return FX_NEW CPDF_Reference(pRef->m_pObjList, obj_num); @@ -322,9 +303,6 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, CFX_MapPtrToPtr* visite } CPDF_Object* CPDF_Object::CloneRef(CPDF_IndirectObjects* pDoc) const { - if (this == NULL) { - return NULL; - } if (m_ObjNum) { return FX_NEW CPDF_Reference(pDoc, m_ObjNum); } @@ -332,9 +310,6 @@ CPDF_Object* CPDF_Object::CloneRef(CPDF_IndirectObjects* pDoc) const } CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const { - if (this == NULL) { - return CFX_WideString(); - } if (m_Type == PDFOBJ_STRING) { return PDF_DecodeText(((CPDF_String*)this)->m_String, pCharMap); } else if (m_Type == PDFOBJ_STREAM) { @@ -349,9 +324,6 @@ CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const } void CPDF_Object::SetUnicodeText(FX_LPCWSTR pUnicodes, int len) { - if (this == NULL) { - return; - } if (m_Type == PDFOBJ_STRING) { ((CPDF_String*)this)->m_String = PDF_EncodeText(pUnicodes, len); } else if (m_Type == PDFOBJ_STREAM) { @@ -411,13 +383,14 @@ CPDF_Array::~CPDF_Array() int size = m_Objects.GetSize(); CPDF_Object** pList = (CPDF_Object**)m_Objects.GetData(); for (int i = 0; i < size; i ++) { - pList[i]->Release(); + if (pList[i]) + pList[i]->Release(); } } CFX_FloatRect CPDF_Array::GetRect() { CFX_FloatRect rect; - if (this == NULL || m_Type != PDFOBJ_ARRAY || m_Objects.GetSize() != 4) { + if (m_Type != PDFOBJ_ARRAY || m_Objects.GetSize() != 4) { return rect; } rect.left = GetNumber(0); @@ -429,7 +402,7 @@ CFX_FloatRect CPDF_Array::GetRect() CFX_AffineMatrix CPDF_Array::GetMatrix() { CFX_AffineMatrix matrix; - if (this == NULL || m_Type != PDFOBJ_ARRAY || m_Objects.GetSize() != 6) { + if (m_Type != PDFOBJ_ARRAY || m_Objects.GetSize() != 6) { return matrix; } matrix.Set(GetNumber(0), GetNumber(1), GetNumber(2), GetNumber(3), GetNumber(4), GetNumber(5)); @@ -437,9 +410,6 @@ CFX_AffineMatrix CPDF_Array::GetMatrix() } CPDF_Object* CPDF_Array::GetElement(FX_DWORD i) const { - if (this == NULL) { - return NULL; - } if (i >= (FX_DWORD)m_Objects.GetSize()) { return NULL; } @@ -447,9 +417,6 @@ CPDF_Object* CPDF_Array::GetElement(FX_DWORD i) const } CPDF_Object* CPDF_Array::GetElementValue(FX_DWORD i) const { - if (this == NULL) { - return NULL; - } if (i >= (FX_DWORD)m_Objects.GetSize()) { return NULL; } @@ -457,23 +424,25 @@ CPDF_Object* CPDF_Array::GetElementValue(FX_DWORD i) const } CFX_ByteString CPDF_Array::GetString(FX_DWORD i) const { - if (this && i < (FX_DWORD)m_Objects.GetSize()) { + if (i < (FX_DWORD)m_Objects.GetSize()) { CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); return p->GetString(); } - return CFX_ByteString(); + else + return CFX_ByteString(); } CFX_ByteStringC CPDF_Array::GetConstString(FX_DWORD i) const { - if (this && i < (FX_DWORD)m_Objects.GetSize()) { + if (i < (FX_DWORD)m_Objects.GetSize()) { CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); return p->GetConstString(); } - return CFX_ByteStringC(); + else + return CFX_ByteStringC(); } int CPDF_Array::GetInteger(FX_DWORD i) const { - if (this == NULL || i >= (FX_DWORD)m_Objects.GetSize()) { + if (i >= (FX_DWORD)m_Objects.GetSize()) { return 0; } CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); @@ -481,7 +450,7 @@ int CPDF_Array::GetInteger(FX_DWORD i) const } FX_FLOAT CPDF_Array::GetNumber(FX_DWORD i) const { - if (this == NULL || i >= (FX_DWORD)m_Objects.GetSize()) { + if (i >= (FX_DWORD)m_Objects.GetSize()) { return 0; } CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); @@ -517,23 +486,25 @@ CPDF_Array* CPDF_Array::GetArray(FX_DWORD i) const } void CPDF_Array::RemoveAt(FX_DWORD i) { - ASSERT(this != NULL && m_Type == PDFOBJ_ARRAY); + ASSERT(m_Type == PDFOBJ_ARRAY); if (i >= (FX_DWORD)m_Objects.GetSize()) { return; } CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); - p->Release(); + if (p) + p->Release(); m_Objects.RemoveAt(i); } void CPDF_Array::SetAt(FX_DWORD i, CPDF_Object* pObj, CPDF_IndirectObjects* pObjs) { - ASSERT(this != NULL && m_Type == PDFOBJ_ARRAY); + ASSERT(m_Type == PDFOBJ_ARRAY); ASSERT(i < (FX_DWORD)m_Objects.GetSize()); if (i >= (FX_DWORD)m_Objects.GetSize()) { return; } CPDF_Object* pOld = (CPDF_Object*)m_Objects.GetAt(i); - pOld->Release(); + if (pOld) + pOld->Release(); if (pObj->GetObjNum()) { ASSERT(pObjs != NULL); pObj = CPDF_Reference::Create(pObjs, pObj->GetObjNum()); @@ -560,29 +531,29 @@ void CPDF_Array::Add(CPDF_Object* pObj, CPDF_IndirectObjects* pObjs) } void CPDF_Array::AddName(const CFX_ByteString& str) { - ASSERT(this != NULL && m_Type == PDFOBJ_ARRAY); + ASSERT(m_Type == PDFOBJ_ARRAY); Add(FX_NEW CPDF_Name(str)); } void CPDF_Array::AddString(const CFX_ByteString& str) { - ASSERT(this != NULL && m_Type == PDFOBJ_ARRAY); + ASSERT(m_Type == PDFOBJ_ARRAY); Add(FX_NEW CPDF_String(str)); } void CPDF_Array::AddInteger(int i) { - ASSERT(this != NULL && m_Type == PDFOBJ_ARRAY); + ASSERT(m_Type == PDFOBJ_ARRAY); Add(FX_NEW CPDF_Number(i)); } void CPDF_Array::AddNumber(FX_FLOAT f) { - ASSERT(this != NULL && m_Type == PDFOBJ_ARRAY); + ASSERT(m_Type == PDFOBJ_ARRAY); CPDF_Number* pNumber = FX_NEW CPDF_Number; pNumber->SetNumber(f); Add(pNumber); } void CPDF_Array::AddReference(CPDF_IndirectObjects* pDoc, FX_DWORD objnum) { - ASSERT(this != NULL && m_Type == PDFOBJ_ARRAY); + ASSERT(m_Type == PDFOBJ_ARRAY); Add(FX_NEW CPDF_Reference(pDoc, objnum)); } FX_BOOL CPDF_Array::Identical(CPDF_Array* pOther) const @@ -601,7 +572,8 @@ CPDF_Dictionary::~CPDF_Dictionary() FX_POSITION pos = m_Map.GetStartPosition(); while (pos) { FX_LPVOID value = m_Map.GetNextValue(pos); - ((CPDF_Object*)value)->Release(); + if (value) + ((CPDF_Object*)value)->Release(); } } FX_POSITION CPDF_Dictionary::GetStartPos() const @@ -619,123 +591,99 @@ CPDF_Object* CPDF_Dictionary::GetNextElement(FX_POSITION& pos, CFX_ByteString& k } CPDF_Object* CPDF_Dictionary::GetElement(FX_BSTR key) const { - if (this == NULL) { - return NULL; - } CPDF_Object* p = NULL; m_Map.Lookup(key, (void*&)p); return p; } CPDF_Object* CPDF_Dictionary::GetElementValue(FX_BSTR key) const { - if (this == NULL) { - return NULL; - } CPDF_Object* p = NULL; m_Map.Lookup(key, (void*&)p); - return p->GetDirect(); + return p ? p->GetDirect() : NULL; } CFX_ByteString CPDF_Dictionary::GetString(FX_BSTR key) const { - if (this) { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); - if (p) { - return p->GetString(); - } - } - return CFX_ByteString(); + CPDF_Object* p = NULL; + m_Map.Lookup(key, (void*&)p); + if (p) + return p->GetString(); + else + return CFX_ByteString(); } CFX_ByteStringC CPDF_Dictionary::GetConstString(FX_BSTR key) const { - if (this) { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); - if (p) { - return p->GetConstString(); - } - } - return CFX_ByteStringC(); + CPDF_Object* p = NULL; + m_Map.Lookup(key, (void*&)p); + if (p) + return p->GetConstString(); + else + return CFX_ByteStringC(); } CFX_WideString CPDF_Dictionary::GetUnicodeText(FX_BSTR key, CFX_CharMap* pCharMap) const { - if (this) { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); - if (p) { - if(p->GetType() == PDFOBJ_REFERENCE) { - p = ((CPDF_Reference*)p)->GetDirect(); - return p->GetUnicodeText(pCharMap); - } else { - return p->GetUnicodeText(pCharMap); - } + CPDF_Object* p = NULL; + m_Map.Lookup(key, (void*&)p); + if (p) { + if(p->GetType() == PDFOBJ_REFERENCE) { + p = ((CPDF_Reference*)p)->GetDirect(); + return p->GetUnicodeText(pCharMap); + } else { + return p->GetUnicodeText(pCharMap); } } return CFX_WideString(); } CFX_ByteString CPDF_Dictionary::GetString(FX_BSTR key, FX_BSTR def) const { - if (this) { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); - if (p) { - return p->GetString(); - } + CPDF_Object* p = NULL; + m_Map.Lookup(key, (void*&)p); + if (p) { + return p->GetString(); } return CFX_ByteString(def); } CFX_ByteStringC CPDF_Dictionary::GetConstString(FX_BSTR key, FX_BSTR def) const { - if (this) { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); - if (p) { - return p->GetConstString(); - } - } - return CFX_ByteStringC(def); + CPDF_Object* p = NULL; + m_Map.Lookup(key, (void*&)p); + if (p) + return p->GetConstString(); + else + return CFX_ByteStringC(def); } int CPDF_Dictionary::GetInteger(FX_BSTR key) const { - if (this) { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); - if (p) { - return p->GetInteger(); - } + CPDF_Object* p = NULL; + m_Map.Lookup(key, (void*&)p); + if (p) { + return p->GetInteger(); } return 0; } int CPDF_Dictionary::GetInteger(FX_BSTR key, int def) const { - if (this) { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); - if (p) { - return p->GetInteger(); - } + CPDF_Object* p = NULL; + m_Map.Lookup(key, (void*&)p); + if (p) { + return p->GetInteger(); } return def; } FX_FLOAT CPDF_Dictionary::GetNumber(FX_BSTR key) const { - if (this) { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); - if (p) { - return p->GetNumber(); - } + CPDF_Object* p = NULL; + m_Map.Lookup(key, (void*&)p); + if (p) { + return p->GetNumber(); } return 0; } FX_BOOL CPDF_Dictionary::GetBoolean(FX_BSTR key, FX_BOOL bDefault) const { - if (this) { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); - if (p && p->GetType() == PDFOBJ_BOOLEAN) { - return p->GetInteger(); - } + CPDF_Object* p = NULL; + m_Map.Lookup(key, (void*&)p); + if (p && p->GetType() == PDFOBJ_BOOLEAN) { + return p->GetInteger(); } return bDefault; } @@ -787,23 +735,19 @@ CFX_AffineMatrix CPDF_Dictionary::GetMatrix(FX_BSTR key) const } FX_BOOL CPDF_Dictionary::KeyExist(FX_BSTR key) const { - if (this == NULL) { - return FALSE; - } FX_LPVOID value; return m_Map.Lookup(key, value); } void CPDF_Dictionary::SetAt(FX_BSTR key, CPDF_Object* pObj, CPDF_IndirectObjects* pObjs) { - ASSERT(this != NULL && m_Type == PDFOBJ_DICTIONARY); + ASSERT(m_Type == PDFOBJ_DICTIONARY); CPDF_Object* p = NULL; m_Map.Lookup(key, (void*&)p); if (p == pObj) { return; } - if (p) { + if (p) p->Release(); - } if (pObj) { if (pObj->GetObjNum()) { ASSERT(pObjs != NULL); @@ -816,12 +760,12 @@ void CPDF_Dictionary::SetAt(FX_BSTR key, CPDF_Object* pObj, CPDF_IndirectObjects } void CPDF_Dictionary::AddValue(FX_BSTR key, CPDF_Object* pObj) { - ASSERT(this != NULL && m_Type == PDFOBJ_DICTIONARY); + ASSERT(m_Type == PDFOBJ_DICTIONARY); m_Map.AddValue(key, pObj); } void CPDF_Dictionary::RemoveAt(FX_BSTR key) { - ASSERT(this != NULL && m_Type == PDFOBJ_DICTIONARY); + ASSERT(m_Type == PDFOBJ_DICTIONARY); CPDF_Object* p = NULL; m_Map.Lookup(key, (void*&)p); if (p == NULL) { @@ -832,7 +776,7 @@ void CPDF_Dictionary::RemoveAt(FX_BSTR key) } void CPDF_Dictionary::ReplaceKey(FX_BSTR oldkey, FX_BSTR newkey) { - ASSERT(this != NULL && m_Type == PDFOBJ_DICTIONARY); + ASSERT(m_Type == PDFOBJ_DICTIONARY); CPDF_Object* p = NULL; m_Map.Lookup(oldkey, (void*&)p); if (p == NULL) { @@ -843,12 +787,6 @@ void CPDF_Dictionary::ReplaceKey(FX_BSTR oldkey, FX_BSTR newkey) } FX_BOOL CPDF_Dictionary::Identical(CPDF_Dictionary* pOther) const { - if (this == NULL) { - if (pOther == NULL) { - return TRUE; - } - return FALSE; - } if (pOther == NULL) { return FALSE; } @@ -860,6 +798,8 @@ FX_BOOL CPDF_Dictionary::Identical(CPDF_Dictionary* pOther) const CFX_ByteString key; FX_LPVOID value; m_Map.GetNextAssoc(pos, key, value); + if (!value) + return FALSE; if (!((CPDF_Object*)value)->IsIdentical(pOther->GetElement(key))) { return FALSE; } @@ -1014,6 +954,9 @@ void CPDF_Stream::InitStream(IFX_FileRead *pFile, CPDF_Dictionary* pDict) } FX_BOOL CPDF_Stream::Identical(CPDF_Stream* pOther) const { + if (!m_pDict) + return pOther->m_pDict ? FALSE : TRUE; + if (!m_pDict->Identical(pOther->m_pDict)) { return FALSE; } diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp index c705ea7357..5e926c31b9 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; } @@ -96,7 +96,8 @@ void CPDF_Parser::CloseParser(FX_BOOL bReParse) m_ObjVersion.RemoveAll(); FX_INT32 iLen = m_Trailers.GetSize(); for (FX_INT32 i = 0; i < iLen; ++i) { - m_Trailers.GetAt(i)->Release(); + if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i)) + trailer->Release(); } m_Trailers.RemoveAll(); if (m_pLinearized) { @@ -1110,7 +1111,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 +1126,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 +1134,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 +1492,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 +2151,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 +2208,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 +2310,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 +2336,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 +2353,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 +2386,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 +2842,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 +3164,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 +3277,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 +3352,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 +3482,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 +3557,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 +3918,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; diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp index 39241e10f4..1452b9d9f9 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp @@ -1082,7 +1082,11 @@ CFX_DIBitmap* CPDF_RenderStatus::LoadSMask(CPDF_Dictionary* pSMaskDict, CPDF_Array* pBC = pSMaskDict->GetArray(FX_BSTRC("BC")); FX_ARGB back_color = 0xff000000; if (pBC) { - pCSObj = pGroup->GetDict()->GetDict(FX_BSTRC("Group"))->GetElementValue(FX_BSTRC("CS")); + CPDF_Dictionary* pDict = pGroup->GetDict(); + if (pDict && pDict->GetDict(FX_BSTRC("Group"))) + pCSObj = pDict->GetDict(FX_BSTRC("Group"))->GetElementValue(FX_BSTRC("CS")); + else + pCSObj = NULL; pCS = m_pContext->m_pDocument->LoadColorSpace(pCSObj); if (pCS) { FX_FLOAT R, G, B; diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp index 91a3725ad7..6befe11ed4 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp @@ -914,7 +914,7 @@ void CPDF_DIBSource::LoadPalette() FX_DWORD CPDF_DIBSource::GetValidBpp() const { FX_DWORD bpc = m_bpc; - CPDF_Object * pFilter = m_pDict->GetElementValue(FX_BSTRC("Filter")); + CPDF_Object * pFilter = m_pDict ? m_pDict->GetElementValue(FX_BSTRC("Filter")) : NULL; if (pFilter) { if (pFilter->GetType() == PDFOBJ_NAME) { CFX_ByteString filter = pFilter->GetString(); diff --git a/core/src/fpdfdoc/doc_annot.cpp b/core/src/fpdfdoc/doc_annot.cpp index 227578a974..8952845570 100644 --- a/core/src/fpdfdoc/doc_annot.cpp +++ b/core/src/fpdfdoc/doc_annot.cpp @@ -165,7 +165,7 @@ void CPDF_Annot::ClearCachedAP() } CFX_ByteString CPDF_Annot::GetSubType() const { - return m_pAnnotDict->GetConstString(FX_BSTRC("Subtype")); + return m_pAnnotDict ? m_pAnnotDict->GetConstString(FX_BSTRC("Subtype")) : CFX_ByteStringC(); } void CPDF_Annot::GetRect(CPDF_Rect& rect) const { @@ -202,7 +202,8 @@ CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, CPDF_Annot::Appeara if (as.IsEmpty()) { CFX_ByteString value = pAnnotDict->GetString(FX_BSTRC("V")); if (value.IsEmpty()) { - value = pAnnotDict->GetDict(FX_BSTRC("Parent"))->GetString(FX_BSTRC("V")); + CPDF_Dictionary* pDict = pAnnotDict->GetDict(FX_BSTRC("Parent")); + value = pDict ? pDict->GetString(FX_BSTRC("V")) : CFX_ByteString(); } if (value.IsEmpty() || !((CPDF_Dictionary*)psub)->KeyExist(value)) { as = FX_BSTRC("Off"); diff --git a/core/src/fpdfdoc/doc_ap.cpp b/core/src/fpdfdoc/doc_ap.cpp index 784d89daed..6a8ab374d2 100644 --- a/core/src/fpdfdoc/doc_ap.cpp +++ b/core/src/fpdfdoc/doc_ap.cpp @@ -10,11 +10,11 @@ #include "../../include/fpdfdoc/fpdf_ap.h" FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { - if (pAnnotDict->GetConstString("Subtype") != FX_BSTRC("Widget")) { + if (!pAnnotDict || pAnnotDict->GetConstString("Subtype") != FX_BSTRC("Widget")) { return FALSE; } CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString(); - FX_DWORD flags = FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger(); + FX_DWORD flags = FPDF_GetFieldAttr(pAnnotDict, "Ff")? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() : 0; if (field_type == "Tx") { return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict); } else if (field_type == "Ch") { @@ -253,7 +253,7 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict if (!pFormDict) { return FALSE; } - CFX_ByteString DA = FPDF_GetFieldAttr(pAnnotDict, "DA")->GetString(); + CFX_ByteString DA = FPDF_GetFieldAttr(pAnnotDict, "DA") ? FPDF_GetFieldAttr(pAnnotDict, "DA")->GetString() : CFX_ByteString(); if (DA.IsEmpty()) { DA = pFormDict->GetString("DA"); } @@ -277,7 +277,7 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict bUseFormRes = TRUE; } CPDF_Dictionary * pDRFontDict = NULL; - if ((pDRFontDict = pDRDict->GetDict("Font"))) { + if (pDRDict && (pDRFontDict = pDRDict->GetDict("Font"))) { pFontDict = pDRFontDict->GetDict(sFontName.Mid(1)); if (!pFontDict && !bUseFormRes) { pDRDict = pFormDict->GetDict(FX_BSTRC("DR")); @@ -430,11 +430,11 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict } switch (nWidgetType) { case 0: { - CFX_WideString swValue = FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText(); - FX_INT32 nAlign = FPDF_GetFieldAttr(pAnnotDict, "Q")->GetInteger(); - FX_DWORD dwFlags = FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger(); - FX_DWORD dwMaxLen = FPDF_GetFieldAttr(pAnnotDict, "MaxLen")->GetInteger(); - CPVT_FontMap map(pDoc, pStreamDict->GetDict("Resources"), pDefFont, sFontName.Right(sFontName.GetLength() - 1)); + CFX_WideString swValue = FPDF_GetFieldAttr(pAnnotDict, "V")? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() : CFX_WideString(); + FX_INT32 nAlign = FPDF_GetFieldAttr(pAnnotDict, "Q")? FPDF_GetFieldAttr(pAnnotDict, "Q")->GetInteger() : 0; + FX_DWORD dwFlags = FPDF_GetFieldAttr(pAnnotDict, "Ff")? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() : 0; + FX_DWORD dwMaxLen = FPDF_GetFieldAttr(pAnnotDict, "MaxLen") ? FPDF_GetFieldAttr(pAnnotDict, "MaxLen")->GetInteger() : 0; + CPVT_FontMap map(pDoc, pStreamDict ? pStreamDict->GetDict("Resources") : NULL , pDefFont, sFontName.Right(sFontName.GetLength() - 1)); CPVT_Provider prd(&map); CPDF_VariableText vt; vt.SetProvider(&prd); @@ -482,8 +482,8 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict } break; case 1: { - CFX_WideString swValue = FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText(); - CPVT_FontMap map(pDoc, pStreamDict->GetDict("Resources"), pDefFont, sFontName.Right(sFontName.GetLength() - 1)); + CFX_WideString swValue = FPDF_GetFieldAttr(pAnnotDict, "V") ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() : CFX_WideString(); + CPVT_FontMap map(pDoc, pStreamDict ? pStreamDict->GetDict("Resources"):NULL, pDefFont, sFontName.Right(sFontName.GetLength() - 1)); CPVT_Provider prd(&map); CPDF_VariableText vt; vt.SetProvider(&prd); @@ -534,11 +534,11 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict } break; case 2: { - CPVT_FontMap map(pDoc, pStreamDict->GetDict("Resources"), pDefFont, sFontName.Right(sFontName.GetLength() - 1)); + CPVT_FontMap map(pDoc, pStreamDict ? pStreamDict->GetDict("Resources"):NULL, pDefFont, sFontName.Right(sFontName.GetLength() - 1)); CPVT_Provider prd(&map); - CPDF_Array * pOpts = FPDF_GetFieldAttr(pAnnotDict, "Opt")->GetArray(); - CPDF_Array * pSels = FPDF_GetFieldAttr(pAnnotDict, "I")->GetArray(); - FX_INT32 nTop = FPDF_GetFieldAttr(pAnnotDict, "TI")->GetInteger(); + CPDF_Array * pOpts = FPDF_GetFieldAttr(pAnnotDict, "Opt") ? FPDF_GetFieldAttr(pAnnotDict, "Opt")->GetArray() : NULL; + CPDF_Array * pSels = FPDF_GetFieldAttr(pAnnotDict, "I") ? FPDF_GetFieldAttr(pAnnotDict, "I")->GetArray() : NULL; + FX_INT32 nTop = FPDF_GetFieldAttr(pAnnotDict, "TI") ? FPDF_GetFieldAttr(pAnnotDict, "TI")->GetInteger() : 0; CFX_ByteTextBuf sBody; if (pOpts) { FX_FLOAT fy = rcBody.top; diff --git a/core/src/fpdfdoc/doc_basic.cpp b/core/src/fpdfdoc/doc_basic.cpp index 199a9a6dec..25f641c52e 100644 --- a/core/src/fpdfdoc/doc_basic.cpp +++ b/core/src/fpdfdoc/doc_basic.cpp @@ -72,7 +72,10 @@ CFX_ByteString CPDF_Dest::GetRemoteName() } CPDF_NameTree::CPDF_NameTree(CPDF_Document* pDoc, FX_BSTR category) { - m_pRoot = pDoc->GetRoot()->GetDict(FX_BSTRC("Names"))->GetDict(category); + if (pDoc->GetRoot() && pDoc->GetRoot()->GetDict(FX_BSTRC("Names"))) + m_pRoot = pDoc->GetRoot()->GetDict(FX_BSTRC("Names"))->GetDict(category); + else + m_pRoot = NULL; } static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, const CFX_ByteString& csName, int& nIndex, CPDF_Array** ppFind, int nLevel = 0) diff --git a/core/src/fpdfdoc/doc_formfield.cpp b/core/src/fpdfdoc/doc_formfield.cpp index 548448696d..e51acf94a1 100644 --- a/core/src/fpdfdoc/doc_formfield.cpp +++ b/core/src/fpdfdoc/doc_formfield.cpp @@ -32,8 +32,8 @@ CPDF_FormField::~CPDF_FormField() } void CPDF_FormField::SyncFieldFlags() { - CFX_ByteString type_name = FPDF_GetFieldAttr(m_pDict, "FT")->GetString(); - FX_DWORD flags = FPDF_GetFieldAttr(m_pDict, "Ff")->GetInteger(); + CFX_ByteString type_name = FPDF_GetFieldAttr(m_pDict, "FT") ? FPDF_GetFieldAttr(m_pDict, "FT")->GetString() : CFX_ByteString(); + FX_DWORD flags = FPDF_GetFieldAttr(m_pDict, "Ff")? FPDF_GetFieldAttr(m_pDict, "Ff")->GetInteger() : 0; m_Flags = 0; if (flags & 1) { m_Flags |= FORMFIELD_READONLY; @@ -485,7 +485,8 @@ int CPDF_FormField::GetSelectedIndex(int index) if (index < 0) { return -1; } - sel_value = ((CPDF_Array*)pValue)->GetElementValue(index)->GetUnicodeText(); + CPDF_Object* elementValue = ((CPDF_Array*)pValue)->GetElementValue(index); + sel_value = elementValue ? elementValue->GetUnicodeText() : CFX_WideString(); } if (index < CountSelectedOptions()) { int iOptIndex = GetSelectedOptionIndex(index); @@ -1076,9 +1077,9 @@ FX_BOOL CPDF_FormField::ClearSelectedOptions(FX_BOOL bNotify) } void CPDF_FormField::LoadDA() { - CFX_ByteString DA = FPDF_GetFieldAttr(m_pDict, "DA")->GetString(); + CFX_ByteString DA = FPDF_GetFieldAttr(m_pDict, "DA") ? FPDF_GetFieldAttr(m_pDict, "DA")->GetString() : CFX_ByteString(); if (DA.IsEmpty()) { - DA = m_pForm->m_pFormDict->GetString("DA"); + DA = m_pForm->m_pFormDict ? m_pForm->m_pFormDict->GetString("DA") : CFX_ByteString(); } if (DA.IsEmpty()) { return; @@ -1086,7 +1087,11 @@ void CPDF_FormField::LoadDA() CPDF_SimpleParser syntax(DA); syntax.FindTagParam("Tf", 2); CFX_ByteString font_name = syntax.GetWord(); - CPDF_Dictionary* pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict(font_name); + CPDF_Dictionary* pFontDict = NULL; + if (m_pForm->m_pFormDict && m_pForm->m_pFormDict->GetDict("DR") && + m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font") ) + pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict(font_name); + if (pFontDict == NULL) { return; } diff --git a/core/src/fpdftext/fpdf_text_int.cpp b/core/src/fpdftext/fpdf_text_int.cpp index 6baf6ad339..8736575952 100644 --- a/core/src/fpdftext/fpdf_text_int.cpp +++ b/core/src/fpdftext/fpdf_text_int.cpp @@ -1442,7 +1442,7 @@ FX_INT32 CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) CPDF_ContentMarkItem& item = pMarkData->GetItem(n); CFX_ByteString tagStr = (CFX_ByteString)item.GetName(); pDict = (CPDF_Dictionary*)item.GetParam(); - CPDF_String* temp = (CPDF_String*)pDict->GetElement(FX_BSTRC("ActualText")); + CPDF_String* temp = (CPDF_String*)(pDict ? pDict->GetElement(FX_BSTRC("ActualText")) : NULL); if (temp) { bExist = TRUE; actText = temp->GetUnicodeText(); diff --git a/core/src/fxcrt/fx_xml_parser.cpp b/core/src/fxcrt/fx_xml_parser.cpp index c3d4b9c506..b7e58a04e1 100644 --- a/core/src/fxcrt/fx_xml_parser.cpp +++ b/core/src/fxcrt/fx_xml_parser.cpp @@ -8,7 +8,7 @@ #include "xml_int.h" CXML_Parser::~CXML_Parser() { - if (m_bOwnedStream) { + if (m_bOwnedStream && m_pDataAcc) { m_pDataAcc->Release(); } } diff --git a/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp b/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp index 0c7cd48553..8e10cc22e3 100644 --- a/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp +++ b/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp @@ -239,14 +239,16 @@ CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString &sAlias) } CFX_ByteString sDA; - - sDA = FPDF_GetFieldAttr(m_pAnnotDict, "DA")->GetString(); + CPDF_Object* pObj; + if ((pObj = FPDF_GetFieldAttr(m_pAnnotDict, "DA"))) + sDA = pObj->GetString(); if (bWidget) { if (sDA.IsEmpty()) { - sDA = FPDF_GetFieldAttr(pAcroFormDict, "DA")->GetString(); + pObj = FPDF_GetFieldAttr(pAcroFormDict, "DA"); + sDA = pObj ? pObj->GetString() : CFX_ByteString(); } } diff --git a/fpdfsdk/src/fpdf_ext.cpp b/fpdfsdk/src/fpdf_ext.cpp index 916cb2069c..93f6e187da 100644 --- a/fpdfsdk/src/fpdf_ext.cpp +++ b/fpdfsdk/src/fpdf_ext.cpp @@ -172,15 +172,15 @@ void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code) if(pRootDict->KeyExist("Names")) { CPDF_Dictionary* pNameDict = pRootDict->GetDict("Names"); - if(pNameDict->KeyExist("EmbeddedFiles")) + if (pNameDict && pNameDict->KeyExist("EmbeddedFiles")) { FPDF_UnSupportError(FPDF_UNSP_DOC_ATTACHMENT); return; } - else if(pNameDict->KeyExist("JavaScript")) + else if (pNameDict && pNameDict->KeyExist("JavaScript")) { CPDF_Dictionary* pJSDict = pNameDict->GetDict("JavaScript"); - CPDF_Array * pArray = pJSDict->GetArray("Names"); + CPDF_Array * pArray = pJSDict ? pJSDict->GetArray("Names") : NULL; if (pArray) { int nCount = pArray->GetCount(); for(int i=0; im_pFormDict; - CPDF_Object* pContentObj = pPageDic->GetElement("Contents"); + CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") : NULL; if(!pContentObj) - pContentObj = pPageDic->GetArray("Contents"); + pContentObj = pPageDic ? pPageDic->GetArray("Contents") : NULL; if(!pContentObj) return FALSE; @@ -260,9 +260,9 @@ DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,FPDF_CLIPPATH clip return; CPDF_Page* pPage = (CPDF_Page*)page; CPDF_Dictionary* pPageDic = pPage->m_pFormDict; - CPDF_Object* pContentObj = pPageDic->GetElement("Contents"); + CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") : NULL; if(!pContentObj) - pContentObj = pPageDic->GetArray("Contents"); + pContentObj = pPageDic ? pPageDic->GetArray("Contents") : NULL; if(!pContentObj) return; diff --git a/fpdfsdk/src/fpdfeditpage.cpp b/fpdfsdk/src/fpdfeditpage.cpp index 4c9fd35108..2e84aa5dcb 100644 --- a/fpdfsdk/src/fpdfeditpage.cpp +++ b/fpdfsdk/src/fpdfeditpage.cpp @@ -102,7 +102,7 @@ DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, int page_index, DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) { CPDF_Page* pPage = (CPDF_Page*)page; - if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") + if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || !pPage->m_pFormDict->GetElement("Type")->GetDirect() || pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page")) { return -1; @@ -112,8 +112,8 @@ DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) int rotate = 0; if(pDict != NULL) { - if(pDict->KeyExist("Rotate")) - rotate = pDict->GetElement("Rotate")->GetDirect()->GetInteger() / 90; + if (pDict->KeyExist("Rotate")) + rotate = pDict->GetElement("Rotate")->GetDirect()? pDict->GetElement("Rotate")->GetDirect()->GetInteger() / 90 : 0; else { if(pDict->KeyExist("Parent")) @@ -123,7 +123,7 @@ DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) { if(pPages->KeyExist("Rotate")) { - rotate = pPages->GetElement("Rotate")->GetDirect()->GetInteger() / 90; + rotate = pPages->GetElement("Rotate")->GetDirect()? pPages->GetElement("Rotate")->GetDirect()->GetInteger() / 90 : 0; break; } else if(pPages->KeyExist("Parent")) @@ -144,7 +144,7 @@ DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, FPDF_PAGEOBJECT page_obj) { CPDF_Page* pPage = (CPDF_Page*)page; - if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") + if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || !pPage->m_pFormDict->GetElement("Type")->GetDirect() || pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page")) { return; @@ -199,7 +199,7 @@ DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, FPDF_PAGEOBJECT pag DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) { CPDF_Page* pPage = (CPDF_Page*)page; - if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") + if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || !pPage->m_pFormDict->GetElement("Type")->GetDirect() || pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page")) { return -1; @@ -263,7 +263,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObje DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page) { CPDF_Page* pPage = (CPDF_Page*)page; - if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") + if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || !pPage->m_pFormDict->GetElement("Type")->GetDirect() || pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page")) { return FALSE; @@ -318,7 +318,7 @@ DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { CPDF_Page* pPage = (CPDF_Page*)page; - if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") + if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || !pPage->m_pFormDict->GetElement("Type")->GetDirect() || pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page")) { return; diff --git a/fpdfsdk/src/fpdfppo.cpp b/fpdfsdk/src/fpdfppo.cpp index a803454cc0..032c3dba39 100644 --- a/fpdfsdk/src/fpdfppo.cpp +++ b/fpdfsdk/src/fpdfppo.cpp @@ -64,7 +64,7 @@ FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document *pDestPDFDoc, CPDF_Document pNewRoot->SetAt("Type", new CPDF_Name("Catalog")); } - CPDF_Dictionary* pNewPages = (CPDF_Dictionary*)pNewRoot->GetElement("Pages")->GetDirect(); + CPDF_Dictionary* pNewPages = (CPDF_Dictionary*)(pNewRoot->GetElement("Pages")? pNewRoot->GetElement("Pages")->GetDirect() : NULL); if(!pNewPages) { pNewPages = new CPDF_Dictionary; @@ -311,7 +311,8 @@ int CPDF_PageOrganizer::GetNewObjId(CPDF_Document *pDoc, CFX_MapPtrToPtr* pMapPt else { CPDF_Object* pClone = pRef->GetDirect()->Clone(); - if(!pClone) return 0; + if(!pClone) + return 0; if(pClone->GetType() == PDFOBJ_DICTIONARY) { diff --git a/fpdfsdk/src/pdfwindow/PWL_Icon.cpp b/fpdfsdk/src/pdfwindow/PWL_Icon.cpp index b85b845553..5e3e6e5586 100644 --- a/fpdfsdk/src/pdfwindow/PWL_Icon.cpp +++ b/fpdfsdk/src/pdfwindow/PWL_Icon.cpp @@ -160,7 +160,7 @@ void CPWL_Icon::GetIconPosition(FX_FLOAT & fLeft, FX_FLOAT & fBottom) //m_pIconFit->GetIconPosition(fLeft,fBottom); fLeft = 0.0f; fBottom = 0.0f; - CPDF_Array* pA = m_pIconFit->m_pDict->GetArray("A"); + CPDF_Array* pA = m_pIconFit->m_pDict ? m_pIconFit->m_pDict->GetArray("A") : NULL; if (pA != NULL) { FX_DWORD dwCount = pA->GetCount(); -- cgit v1.2.3