[Git][reproducible-builds/diffoscope][master] 3 commits: Don't reject Debian .changes files if they contain non-printable characters....

Chris Lamb (@lamby) gitlab at salsa.debian.org
Sun Nov 7 14:49:20 UTC 2021



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
c45f587b by Chris Lamb at 2021-11-07T14:49:07+00:00
Don't reject Debian .changes files if they contain non-printable characters. (Closes: reproducible-builds/diffoscope#286)

- - - - -
63ffe02e by Chris Lamb at 2021-11-07T14:49:07+00:00
Log the reason if we cannot load a Debian .changes file.

- - - - -
e9839553 by Chris Lamb at 2021-11-07T14:49:07+00:00
Continue loading a .changes file if the referenced files do not exist, but include a comment in the returned diff.

- - - - -


2 changed files:

- diffoscope/comparators/debian.py
- tests/comparators/test_debian.py


Changes:

=====================================
diffoscope/comparators/debian.py
=====================================
@@ -217,7 +217,10 @@ class DebControlFile(File):
 class DotChangesFile(DebControlFile):
     DESCRIPTION = "Debian .changes files"
     FILE_EXTENSION_SUFFIX = {".changes"}
-    FILE_TYPE_RE = re.compile(r"^(ASCII text|UTF-8 Unicode text)")
+
+    # .changes files can be identified "data" if they contain non-printable
+    # characters (Re: reproducible-builds/diffoscope#286)
+    FILE_TYPE_RE = re.compile(r"^(ASCII text|UTF-8 Unicode text|data)")
 
     @classmethod
     def recognizes(cls, file):
@@ -226,13 +229,19 @@ class DotChangesFile(DebControlFile):
 
         try:
             file._deb822 = Changes(filename=file.path)
-        except ChangesFileException:
+        except ChangesFileException as exc:
+            logger.warning(
+                f"Rejecting {file.path} as a Debian .changes file: {exc}"
+            )
             return False
 
         try:
+            file.validation_msg = None
             file._deb822.validate("sha256", check_signature=False)
-        except FileNotFoundError:
-            return False
+        except FileNotFoundError as exc:
+            # Continue even though this .changes file may be invalid
+            file.validation_msg = f"{os.path.basename(file.path)} is missing referenced files: {exc}"
+            logger.warning(file.validation_msg)
 
         return True
 
@@ -242,6 +251,10 @@ class DotChangesFile(DebControlFile):
         if differences is None:
             return None
 
+        for x in (self, other):
+            if x.validation_msg:
+                differences.add_comment(x.validation_msg)
+
         other_deb822 = self._get_deb822(other)
 
         files = zip(self._deb822.get("Files"), other_deb822.get("Files"))


=====================================
tests/comparators/test_debian.py
=====================================
@@ -113,7 +113,8 @@ def test_dot_changes_invalid(tmpdir):
     shutil.copy(TEST_DOT_CHANGES_FILE1_PATH, dot_changes_path)
     # we don't copy the referenced .deb
     identified = specialize(FilesystemFile(dot_changes_path))
-    assert not isinstance(identified, DotChangesFile)
+    # ... but it is identified regardless
+    assert isinstance(identified, DotChangesFile)
 
 
 def test_dot_changes_no_differences(dot_changes1):



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/aea11a3ba8d9f116827b685cd91075bd8a64ead2...e9839553b88e6b8933627488a5bb2f9e228a92d1

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/aea11a3ba8d9f116827b685cd91075bd8a64ead2...e9839553b88e6b8933627488a5bb2f9e228a92d1
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20211107/8a676fcf/attachment.htm>


More information about the rb-commits mailing list