Land: Protect against a seg fault in CPDF_StructElementImpl constructor.
[pdfium.git] / core / src / fpdfdoc / doc_tagged.cpp
index 5510420..c5fe39b 100644 (file)
@@ -192,8 +192,11 @@ FX_BOOL CPDF_StructTreeImpl::AddTopLevelNode(CPDF_Dictionary* pDict, CPDF_Struct
         FX_DWORD i;
         FX_BOOL bSave = FALSE;
         for (i = 0; i < pTopKids->GetCount(); i ++) {
-            CPDF_Reference* pKidRef = (CPDF_Reference*)pTopKids->GetElement(i);
-            if (pKidRef->GetType() != PDFOBJ_REFERENCE || pKidRef->GetRefObjNum() != pDict->GetObjNum()) {
+            CPDF_Object* pKidRef = pTopKids->GetElement(i);
+            if (pKidRef == NULL || pKidRef->GetType() != PDFOBJ_REFERENCE) {
+                continue;
+            }
+            if (((CPDF_Reference*) pKidRef)->GetRefObjNum() != pDict->GetObjNum()) {
                 continue;
             }
             if (m_Kids[i]) {
@@ -214,9 +217,11 @@ CPDF_StructElementImpl::CPDF_StructElementImpl(CPDF_StructTreeImpl* pTree, CPDF_
     m_pTree = pTree;
     m_pDict = pDict;
     m_Type = pDict->GetString(FX_BSTRC("S"));
-    CFX_ByteString mapped = pTree->m_pRoleMap->GetString(m_Type);
-    if (!mapped.IsEmpty()) {
-        m_Type = mapped;
+    if (pTree->m_pRoleMap) {
+        CFX_ByteString mapped = pTree->m_pRoleMap->GetString(m_Type);
+        if (!mapped.IsEmpty()) {
+            m_Type = mapped;
+        }
     }
     m_pParent = pParent;
     LoadKids(pDict);