[diffoscope] 03/03: Don't crash on invalid archives, printing a useful error instead. (Closes: #833697)
Chris Lamb
chris at chris-lamb.co.uk
Sat Apr 15 00:00:30 CEST 2017
This is an automated email from the git hooks/post-receive script.
lamby pushed a commit to branch experimental
in repository diffoscope.
commit 82fbe27785f08d3623073eb98a3a4670b02fd2dc
Author: Chris Lamb <lamby at debian.org>
Date: Fri Apr 14 23:00:10 2017 +0100
Don't crash on invalid archives, printing a useful error instead. (Closes: #833697)
Signed-off-by: Chris Lamb <lamby at debian.org>
---
diffoscope/comparators/utils/file.py | 9 ++++++++-
diffoscope/comparators/utils/libarchive.py | 10 +++++++---
diffoscope/exc.py | 5 +++++
3 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/diffoscope/comparators/utils/file.py b/diffoscope/comparators/utils/file.py
index 611aa93..97d829b 100644
--- a/diffoscope/comparators/utils/file.py
+++ b/diffoscope/comparators/utils/file.py
@@ -24,7 +24,8 @@ import magic
import logging
import subprocess
-from diffoscope.exc import RequiredToolNotFound, OutputParsingError
+from diffoscope.exc import RequiredToolNotFound, OutputParsingError, \
+ ContainerExtractionError
from diffoscope.tools import tool_required
from diffoscope.profiling import profile
from diffoscope.difference import Difference
@@ -274,6 +275,12 @@ class File(object, metaclass=abc.ABCMeta):
return None
difference.add_comment("Error parsing output of `%s` for %s" %
(e.command, e.object_class))
+ except ContainerExtractionError as e:
+ difference = self.compare_bytes(other, source=source)
+ if difference is None:
+ return None
+ difference.add_comment("Error extracting '{}', falling back to "
+ "binary comparison ('{}')".format(e.pathname, e.wrapped_exc))
return difference
return self.compare_bytes(other, source)
diff --git a/diffoscope/comparators/utils/libarchive.py b/diffoscope/comparators/utils/libarchive.py
index b8ba582..2271591 100644
--- a/diffoscope/comparators/utils/libarchive.py
+++ b/diffoscope/comparators/utils/libarchive.py
@@ -25,6 +25,7 @@ import logging
import libarchive
import collections
+from diffoscope.exc import ContainerExtractionError
from diffoscope.excludes import any_excluded
from diffoscope.tempfiles import get_temporary_directory
@@ -227,9 +228,12 @@ class LibarchiveContainer(Archive):
logger.debug("Extracting %s to %s", entry.pathname, dst)
os.makedirs(os.path.dirname(dst), exist_ok=True)
- with open(dst, 'wb') as f:
- for block in entry.get_blocks():
- f.write(block)
+ try:
+ with open(dst, 'wb') as f:
+ for block in entry.get_blocks():
+ f.write(block)
+ except Exception as exc:
+ raise ContainerExtractionError(entry.pathname, exc)
logger.debug(
"Extracted %d entries from %s to %s",
diff --git a/diffoscope/exc.py b/diffoscope/exc.py
index daffbae..64c5810 100644
--- a/diffoscope/exc.py
+++ b/diffoscope/exc.py
@@ -38,3 +38,8 @@ class RequiredToolNotFound(Exception):
return None
return providers.get(get_current_os(), None)
+
+class ContainerExtractionError(Exception):
+ def __init__(self, pathname, wrapped_exc):
+ self.pathname = pathname
+ self.wrapped_exc = wrapped_exc
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list