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