76f8c5
From 77a30e94d96220d7e22dff5b3f0a7f296f01b118 Mon Sep 17 00:00:00 2001
76f8c5
From: Adam Reichold <adam.reichold@t-online.de>
76f8c5
Date: Tue, 6 Nov 2018 09:13:41 +0100
76f8c5
Subject: [PATCH] pdfdetach: Check for valid embedded file before trying to
76f8c5
 save it.
76f8c5
76f8c5
Closes #661
76f8c5
---
76f8c5
 utils/pdfdetach.cc | 14 ++++++++++++--
76f8c5
 1 file changed, 12 insertions(+), 2 deletions(-)
76f8c5
76f8c5
diff --git a/utils/pdfdetach.cc b/utils/pdfdetach.cc
76f8c5
index 846584a4..a8720c64 100644
76f8c5
--- a/utils/pdfdetach.cc
76f8c5
+++ b/utils/pdfdetach.cc
76f8c5
@@ -251,7 +251,12 @@ int main(int argc, char *argv[]) {
76f8c5
       }
76f8c5
       *p = '\0';
76f8c5
 
76f8c5
-      if (!fileSpec->getEmbeddedFile()->save(path)) {
76f8c5
+      EmbFile *embFile = fileSpec->getEmbeddedFile();
76f8c5
+      if (!embFile || !embFile->isOk()) {
76f8c5
+	exitCode = 3;
76f8c5
+	goto err2;
76f8c5
+      }
76f8c5
+      if (!embFile->save(path)) {
76f8c5
 	error(errIO, -1, "Error saving embedded file as '{0:s}'", p);
76f8c5
 	exitCode = 2;
76f8c5
 	goto err2;
76f8c5
@@ -296,7 +301,12 @@ int main(int argc, char *argv[]) {
76f8c5
       p = path;
76f8c5
     }
76f8c5
 
76f8c5
-    if (!fileSpec->getEmbeddedFile()->save(p)) {
76f8c5
+    EmbFile *embFile = fileSpec->getEmbeddedFile();
76f8c5
+    if (!embFile || !embFile->isOk()) {
76f8c5
+      exitCode = 3;
76f8c5
+      goto err2;
76f8c5
+    }
76f8c5
+    if (!embFile->save(p)) {
76f8c5
       error(errIO, -1, "Error saving embedded file as '{0:s}'", p);
76f8c5
       exitCode = 2;
76f8c5
       goto err2;
76f8c5
-- 
76f8c5
2.19.1
76f8c5