From 1316c7a41f4dd7276f404f775ebb5fef2d24ab1c Mon Sep 17 00:00:00 2001 From: Albert Astals Cid <aacid@kde.org> Date: Fri, 8 Sep 2017 18:29:42 +0200 Subject: Annot: Fix crash on broken files Bug #102607 Index: poppler-0.41.0/poppler/Annot.cc =================================================================== --- poppler-0.41.0.orig/poppler/Annot.cc +++ poppler-0.41.0/poppler/Annot.cc @@ -6982,26 +6982,30 @@ AnnotRichMedia::Configuration::Configura } else if (!strcmp(name, "Video")) { type = typeVideo; } else { - // determine from first instance + // determine from first non null instance + type = typeFlash; // default in case all instances are null if (instances && nInstances > 0) { - AnnotRichMedia::Instance *instance = instances[0]; - switch (instance->getType()) { - case AnnotRichMedia::Instance::type3D: - type = type3D; - break; - case AnnotRichMedia::Instance::typeFlash: - type = typeFlash; - break; - case AnnotRichMedia::Instance::typeSound: - type = typeSound; - break; - case AnnotRichMedia::Instance::typeVideo: - type = typeVideo; - break; - default: - type = typeFlash; - break; - } + for (int i = 0; i < nInstances; ++i) { + AnnotRichMedia::Instance *instance = instances[i]; + if (instance) { + switch (instance->getType()) { + case AnnotRichMedia::Instance::type3D: + type = type3D; + break; + case AnnotRichMedia::Instance::typeFlash: + type = typeFlash; + break; + case AnnotRichMedia::Instance::typeSound: + type = typeSound; + break; + case AnnotRichMedia::Instance::typeVideo: + type = typeVideo; + break; + } + // break the loop since we found the first non null instance + break; + } + } } } }