3587f3
From 7f87dc10b6adccd6d1b977a28b064add254aa2da Mon Sep 17 00:00:00 2001
3587f3
From: Adam Reichold <adam.reichold@t-online.de>
3587f3
Date: Thu, 27 Dec 2018 11:54:53 +0100
3587f3
Subject: [PATCH] Do not try to construct invalid rich media annotation assets.
3587f3
 Closes #703
3587f3
3587f3
---
3587f3
 poppler/Annot.cc | 24 +++++++++++++-----------
3587f3
 1 file changed, 13 insertions(+), 11 deletions(-)
3587f3
3587f3
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
3587f3
index 2e4770ab..1750dc70 100644
3587f3
--- a/poppler/Annot.cc
3587f3
+++ b/poppler/Annot.cc
3587f3
@@ -6418,20 +6418,22 @@ AnnotRichMedia::Content::Content(Dict *dict) {
3587f3
   if (obj1.isDict()) {
3587f3
     Object obj2 = obj1.getDict()->lookup("Names");
3587f3
     if (obj2.isArray()) {
3587f3
-      nAssets = obj2.arrayGetLength() / 2;
3587f3
+      const int length = obj2.arrayGetLength() / 2;
3587f3
 
3587f3
-      assets = (Asset **)gmallocn(nAssets, sizeof(Asset *));
3587f3
+      assets = (Asset **)gmallocn(length, sizeof(Asset *));
3587f3
+      for (int i = 0; i < length; ++i) {
3587f3
+	Object objKey = obj2.arrayGet(2 * i);
3587f3
+	Object objVal = obj2.arrayGet(2 * i + 1);
3587f3
 
3587f3
-      int counter = 0;
3587f3
-      for (int i = 0; i < nAssets; ++i) {
3587f3
-        assets[counter] = new AnnotRichMedia::Asset;
3587f3
-
3587f3
-        Object objKey = obj2.arrayGet(i * 2);
3587f3
-        assets[counter]->fileSpec = obj2.arrayGet(i * 2 + 1);
3587f3
-
3587f3
-        assets[counter]->name = new GooString( objKey.getString() );
3587f3
-        ++counter;
3587f3
+	if (!objKey.isString() || objVal.isNull()) {
3587f3
+	  error(errSyntaxError, -1, "Bad Annot Asset");
3587f3
+	  continue;
3587f3
+	}
3587f3
 
3587f3
+	assets[nAssets] = new AnnotRichMedia::Asset;
3587f3
+	assets[nAssets]->name = new GooString( objKey.getString() );
3587f3
+	assets[nAssets]->fileSpec = std::move(objVal);
3587f3
+	++nAssets;
3587f3
       }
3587f3
     }
3587f3
   }
3587f3
-- 
3587f3
2.20.1
3587f3