summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_parser
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/fpdfapi/fpdf_parser')
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp8
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp8
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_encrypt.cpp8
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp8
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_filters.cpp4
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp251
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp55
7 files changed, 151 insertions, 191 deletions
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;