--- a/podofo/src/doc/PdfPagesTree.cpp
+++ b/podofo/src/doc/PdfPagesTree.cpp
@@ -412,6 +412,9 @@ PdfObject* PdfPagesTree::GetPageNodeFromArray( int nPageNum, const PdfArray & rK
         }
 
         PdfObject* pgObject = GetRoot()->GetOwner()->GetObject( rVar.GetReference() );
+		if(pgObject==NULL) {
+			PODOFO_RAISE_ERROR_INFO( ePdfError_PageNotFound, "Invalid reference." );
+		}
         //printf("Reading %s\n", pgObject->Reference().ToString().c_str());
         // make sure the object is a /Page and not a /Pages with a single kid
         if( this->IsTypePage(pgObject) ) 
@@ -427,6 +430,9 @@ PdfObject* PdfPagesTree::GetPageNodeFromArray( int nPageNum, const PdfArray & rK
 
             rLstParents.push_back( pgObject );
             rVar = *(pgObject->GetDictionary().GetKey( "Kids" ));
+        } else {
+            // Reference to unexpected object
+            PODOFO_RAISE_ERROR_INFO( ePdfError_PageNotFound, "Reference to unexpected object." );
         }
     }
