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