[poppler] Branch 'poppler-0.8' - poppler/OptionalContent.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Sun May 11 14:47:17 PDT 2008


 poppler/OptionalContent.cc |   33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

New commits:
commit 295d12e387ce3086c07805081ae00b70e251afab
Author: Albert Astals Cid <aacid at kde.org>
Date:   Sun May 11 23:44:50 2008 +0200

    Check the OC we found exists before using it
    
    Fixes crash http://bugs.freedesktop.org/show_bug.cgi?id=15899

diff --git a/poppler/OptionalContent.cc b/poppler/OptionalContent.cc
index d7bf628..64621a7 100644
--- a/poppler/OptionalContent.cc
+++ b/poppler/OptionalContent.cc
@@ -162,12 +162,18 @@ OptionalContentGroup* OCGs::findOcgByRef( const Ref &ref)
 {
   //TODO: make this more efficient
   OptionalContentGroup *ocg = NULL;
-  for (int i=0; i < optionalContentGroups->getLength(); ++i) {
-    ocg = (OptionalContentGroup*)optionalContentGroups->get(i);
-    if ( (ocg->ref().num == ref.num) && (ocg->ref().gen == ref.gen) ) {
-      return ocg;
+  if (optionalContentGroups != NULL)
+  {
+    for (int i=0; i < optionalContentGroups->getLength(); ++i) {
+      ocg = (OptionalContentGroup*)optionalContentGroups->get(i);
+      if ( (ocg->ref().num == ref.num) && (ocg->ref().gen == ref.gen) ) {
+        return ocg;
+      }
     }
   }
+
+  error(-1, "Could not find a OCG with Ref (%d:%d)", ref.num, ref.gen);
+
   // not found
   return NULL;
 }
@@ -208,7 +214,7 @@ bool OCGs::optContentIsVisible( Object *dictRef )
       }
     } else if (ocg.isRef()) {
       OptionalContentGroup* oc = findOcgByRef( ocg.getRef() );      
-      if ( oc->state() == OptionalContentGroup::Off ) {
+      if ( !oc || oc->state() == OptionalContentGroup::Off ) {
 	result = false;
       } else {
 	result = true ;
@@ -218,13 +224,10 @@ bool OCGs::optContentIsVisible( Object *dictRef )
     policy.free();
   } else if ( dictType.isName("OCG") ) {
     OptionalContentGroup* oc = findOcgByRef( dictRef->getRef() );
-    if ( oc ) {
-//       printf("Found valid group object\n");
-      if ( oc->state() == OptionalContentGroup::Off ) {
-	result=false;
-      }
+    if ( !oc || oc->state() == OptionalContentGroup::Off ) {
+      result=false;
     }
-  } 
+  }
   dictType.free();
   dictObj.free();
   // printf("visibility: %s\n", result? "on" : "off");
@@ -238,7 +241,7 @@ bool OCGs::allOn( Array *ocgArray )
     ocgArray->getNF(i, &ocgItem);
     if (ocgItem.isRef()) {
       OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );      
-      if ( oc->state() == OptionalContentGroup::Off ) {
+      if ( oc && oc->state() == OptionalContentGroup::Off ) {
 	return false;
       }
     }
@@ -253,7 +256,7 @@ bool OCGs::allOff( Array *ocgArray )
     ocgArray->getNF(i, &ocgItem);
     if (ocgItem.isRef()) {
       OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );      
-      if ( oc->state() == OptionalContentGroup::On ) {
+      if ( oc && oc->state() == OptionalContentGroup::On ) {
 	return false;
       }
     }
@@ -268,7 +271,7 @@ bool OCGs::anyOn( Array *ocgArray )
     ocgArray->getNF(i, &ocgItem);
     if (ocgItem.isRef()) {
       OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );      
-      if ( oc->state() == OptionalContentGroup::On ) {
+      if ( oc && oc->state() == OptionalContentGroup::On ) {
 	return true;
       }
     }
@@ -283,7 +286,7 @@ bool OCGs::anyOff( Array *ocgArray )
     ocgArray->getNF(i, &ocgItem);
     if (ocgItem.isRef()) {
       OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );      
-      if ( oc->state() == OptionalContentGroup::Off ) {
+      if ( oc && oc->state() == OptionalContentGroup::Off ) {
 	return true;
       }
     }


More information about the poppler mailing list