[diffoscope] 01/01: Don't fail when run under perversely recursive input files. (Closes: #780761)

Chris Lamb chris at chris-lamb.co.uk
Sat May 13 10:40:47 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 80d380823b2b39109659084c57d26ee2ef5e9ad4
Author: Chris Lamb <lamby at debian.org>
Date:   Sat May 13 10:02:35 2017 +0200

    Don't fail when run under perversely recursive input files. (Closes: #780761)
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 diffoscope/comparators/utils/container.py | 5 +++++
 diffoscope/comparators/utils/file.py      | 9 +++++++++
 diffoscope/config.py                      | 1 +
 tests/data/quine_deb_expected_diff        | 5 +++++
 tests/test_quines.py                      | 9 +++------
 5 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/diffoscope/comparators/utils/container.py b/diffoscope/comparators/utils/container.py
index 57fb10a..5962723 100644
--- a/diffoscope/comparators/utils/container.py
+++ b/diffoscope/comparators/utils/container.py
@@ -46,6 +46,11 @@ class Container(object, metaclass=abc.ABCMeta):
     def __init__(self, source):
         self._source = source
 
+        # Keep a count of how "nested" we are
+        self.depth = 0
+        if hasattr(source, 'container') and source.container is not None:
+            self.depth = source.container.depth + 1
+
     @property
     def source(self):
         return self._source
diff --git a/diffoscope/comparators/utils/file.py b/diffoscope/comparators/utils/file.py
index 97d829b..e5f6a9f 100644
--- a/diffoscope/comparators/utils/file.py
+++ b/diffoscope/comparators/utils/file.py
@@ -27,6 +27,7 @@ import subprocess
 from diffoscope.exc import RequiredToolNotFound, OutputParsingError, \
     ContainerExtractionError
 from diffoscope.tools import tool_required
+from diffoscope.config import Config
 from diffoscope.profiling import profile
 from diffoscope.difference import Difference
 
@@ -194,6 +195,14 @@ class File(object, metaclass=abc.ABCMeta):
         if hasattr(self, 'compare_details'):
             details.extend(self.compare_details(other, source))
         if self.as_container:
+            # Don't recursve forever on archive quines, etc.
+            depth = self._as_container.depth
+            if depth >= Config().max_container_depth:
+                msg = "Reached max container depth ({})".format(depth)
+                logger.debug(msg)
+                difference.add_comment(msg)
+                return difference
+
             details.extend(self.as_container.compare(other.as_container))
 
         details = [x for x in details if x]
diff --git a/diffoscope/config.py b/diffoscope/config.py
index 6a9eff5..8f6a229 100644
--- a/diffoscope/config.py
+++ b/diffoscope/config.py
@@ -35,6 +35,7 @@ class Config(object):
     enforce_constraints = True
     excludes = ()
     compute_visual_diffs = False
+    max_container_depth = 50
 
     _singleton = {}
 
diff --git a/tests/data/quine_deb_expected_diff b/tests/data/quine_deb_expected_diff
new file mode 100644
index 0000000..91fb2da
--- /dev/null
+++ b/tests/data/quine_deb_expected_diff
@@ -0,0 +1,5 @@
+@@ -1,3 +1,3 @@
+ -rw-r--r--   0     1000     1000        4 2015-03-18 15:43:32.000000 debian-binary
+ -rw-r--r--   0     1000     1000      149 2015-03-18 19:41:42.000000 control.tar.gz
+--rw-r--r--   0     1000     1000      301 2015-03-18 19:39:56.000000 data.tar.gz
++-rw-r--r--   0     1000     1000      302 2015-03-18 19:44:07.000000 data.tar.gz
diff --git a/tests/test_quines.py b/tests/test_quines.py
index 4f99b2d..9cd3418 100644
--- a/tests/test_quines.py
+++ b/tests/test_quines.py
@@ -63,12 +63,9 @@ def test_identification_deb(quine3, quine4):
 
 @pytest.fixture
 def differences_deb(quine3, quine4):
-    # These tests currently fail
-    with pytest.raises(RecursionError):
-        return quine3.compare(quine4).details
+    return quine3.compare(quine4).details
 
 
 def test_differences_deb(differences_deb):
-    assert differences_deb is None
-    #expected_diff = get_data('quine_deb_expected_diff')
-    #assert differences_deb[0].unified_diff == expected_diff
+    expected_diff = get_data('quine_deb_expected_diff')
+    assert differences_deb[0].unified_diff == expected_diff

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list