04d40c9
From 6bf7212c44d0131c8f8227a4a4dadc52a3afebd9 Mon Sep 17 00:00:00 2001
04d40c9
From: Albert Astals Cid <aacid@kde.org>
04d40c9
Date: Fri, 8 Sep 2017 18:29:42 +0200
04d40c9
Subject: [PATCH 1/3] Annot: Fix crash on broken files
04d40c9
04d40c9
Bug #102607
04d40c9
04d40c9
(cherry picked from commit 1316c7a41f4dd7276f404f775ebb5fef2d24ab1c)
04d40c9
---
04d40c9
 poppler/Annot.cc | 42 +++++++++++++++++++++++-------------------
04d40c9
 1 file changed, 23 insertions(+), 19 deletions(-)
04d40c9
04d40c9
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
04d40c9
index 974b098b..27b698db 100644
04d40c9
--- a/poppler/Annot.cc
04d40c9
+++ b/poppler/Annot.cc
04d40c9
@@ -6982,26 +6982,30 @@ AnnotRichMedia::Configuration::Configuration(Dict *dict)
04d40c9
     } else if (!strcmp(name, "Video")) {
04d40c9
       type = typeVideo;
04d40c9
     } else {
04d40c9
-      // determine from first instance
04d40c9
+      // determine from first non null instance
04d40c9
+      type = typeFlash; // default in case all instances are null
04d40c9
       if (instances && nInstances > 0) {
04d40c9
-        AnnotRichMedia::Instance *instance = instances[0];
04d40c9
-        switch (instance->getType()) {
04d40c9
-          case AnnotRichMedia::Instance::type3D:
04d40c9
-            type = type3D;
04d40c9
-            break;
04d40c9
-          case AnnotRichMedia::Instance::typeFlash:
04d40c9
-            type = typeFlash;
04d40c9
-            break;
04d40c9
-          case AnnotRichMedia::Instance::typeSound:
04d40c9
-            type = typeSound;
04d40c9
-            break;
04d40c9
-          case AnnotRichMedia::Instance::typeVideo:
04d40c9
-            type = typeVideo;
04d40c9
-            break;
04d40c9
-          default:
04d40c9
-            type = typeFlash;
04d40c9
-            break;
04d40c9
-        }
04d40c9
+	for (int i = 0; i < nInstances; ++i) {
04d40c9
+	  AnnotRichMedia::Instance *instance = instances[i];
04d40c9
+	  if (instance) {
04d40c9
+	    switch (instance->getType()) {
04d40c9
+	      case AnnotRichMedia::Instance::type3D:
04d40c9
+		type = type3D;
04d40c9
+		break;
04d40c9
+	      case AnnotRichMedia::Instance::typeFlash:
04d40c9
+		type = typeFlash;
04d40c9
+		break;
04d40c9
+	      case AnnotRichMedia::Instance::typeSound:
04d40c9
+		type = typeSound;
04d40c9
+		break;
04d40c9
+	      case AnnotRichMedia::Instance::typeVideo:
04d40c9
+		type = typeVideo;
04d40c9
+		break;
04d40c9
+	    }
04d40c9
+	    // break the loop since we found the first non null instance
04d40c9
+	    break;
04d40c9
+	  }
04d40c9
+	}
04d40c9
       }
04d40c9
     }
04d40c9
   }
04d40c9
-- 
04d40c9
2.14.1
04d40c9