Blame SOURCES/no_crash_extract_error_1263315.patch

c5477d
From 7c4ffe3b7dc35f6ceb2f97b985f6d6f9b25ba4c0 Mon Sep 17 00:00:00 2001
c5477d
From: Vratislav Podzimek <vpodzime@redhat.com>
c5477d
Date: Wed, 25 May 2016 18:24:02 +0200
c5477d
Subject: [PATCH 08/13] Avoid crashes on extraction errors
c5477d
c5477d
If there is an IOError or some problem with the cpio archive, we need to
c5477d
transform the exception into our own so that it is properly caught and processed
c5477d
in the best possible way in the UI layer.
c5477d
c5477d
Resolves: rhbz#1263315
c5477d
---
c5477d
 org_fedora_oscap/common.py | 21 ++++++++++++---------
c5477d
 1 file changed, 12 insertions(+), 9 deletions(-)
c5477d
c5477d
diff --git a/org_fedora_oscap/common.py b/org_fedora_oscap/common.py
c5477d
index 8b2e84f..684f8ab 100644
c5477d
--- a/org_fedora_oscap/common.py
c5477d
+++ b/org_fedora_oscap/common.py
c5477d
@@ -403,17 +403,20 @@ def _extract_rpm(rpm_path, root="/", ensure_has_files=None):
c5477d
             msg = "File '%s' not found in the archive '%s'" % (fpath, rpm_path)
c5477d
             raise ExtractionError(msg)
c5477d
 
c5477d
-    for entry in entries:
c5477d
-        dirname = os.path.dirname(entry.name.lstrip("."))
c5477d
-        out_dir = os.path.normpath(root + dirname)
c5477d
-        utils.ensure_dir_exists(out_dir)
c5477d
+    try:
c5477d
+        for entry in entries:
c5477d
+            dirname = os.path.dirname(entry.name.lstrip("."))
c5477d
+            out_dir = os.path.normpath(root + dirname)
c5477d
+            utils.ensure_dir_exists(out_dir)
c5477d
 
c5477d
-        out_fpath = os.path.normpath(root + entry.name.lstrip("."))
c5477d
-        with open(out_fpath, "wb") as out_file:
c5477d
-            buf = entry.read(IO_BUF_SIZE)
c5477d
-            while buf:
c5477d
-                out_file.write(buf)
c5477d
+            out_fpath = os.path.normpath(root + entry.name.lstrip("."))
c5477d
+            with open(out_fpath, "wb") as out_file:
c5477d
                 buf = entry.read(IO_BUF_SIZE)
c5477d
+                while buf:
c5477d
+                    out_file.write(buf)
c5477d
+                    buf = entry.read(IO_BUF_SIZE)
c5477d
+    except (IOError, cpioarchive.CpioError) as e:
c5477d
+        raise ExtractionError(e)
c5477d
 
c5477d
     # cleanup
c5477d
     archive.close()
c5477d
-- 
c5477d
2.5.5
c5477d