[Git][reproducible-builds/diffoscope][master] file: don't crash when hashing directory symlinks
Chris Lamb (@lamby)
gitlab at salsa.debian.org
Sat Aug 24 16:54:09 UTC 2024
Chris Lamb pushed to branch master at Reproducible Builds / diffoscope
Commits:
f545e70a by Sergei Trofimovich at 2024-08-24T13:55:27+01:00
file: don't crash when hashing directory symlinks
Noticed the crash today when tried to compare glibc directories:
$ diffoscope /nix/store/shybiq9nx8j3sp3ax2gb6c4lni1djabl-glibc-2.39-52/ /nix/store/bsin40d5wph9yr28rrd0j0zq6qm6982s-glibc-2.39-52/
File "...-diffoscope-276/lib/python3.12/site-packages/diffoscope/comparators/directory.py", line 280, in compare
differences.extend(my_container.compare(other_container))
File "...-diffoscope-276/lib/python3.12/site-packages/diffoscope/comparators/utils/container.py", line 164, in comparisons
for my_name, other_name, score in self.perform_fuzzy_matching(
File "...-diffoscope-276/lib/python3.12/site-packages/diffoscope/comparators/utils/fuzzy.py", line 45, in perform_fuzzy_matching
if file1.is_directory() or not file1.fuzzy_hash:
^^^^^^^^^^^^^^^^
File "...-diffoscope-276/lib/python3.12/site-packages/diffoscope/comparators/utils/file.py", line 380, in fuzzy_hash
self._fuzzy_hash = calc()
^^^^^^
File "...-diffoscope-276/lib/python3.12/site-packages/diffoscope/comparators/utils/file.py", line 368, in calc
with open(self.path, "rb") as f:
^^^^^^^^^^^^^^^^^^^^^
IsADirectoryError: [Errno 21] Is a directory: '/nix/store/shybiq9nx8j3sp3ax2gb6c4lni1djabl-glibc-2.39-52/lib64'
It looks like `diffoscope` was confused by a symlink to a directory:
$ ls -l /nix/store/shybiq9nx8j3sp3ax2gb6c4lni1djabl-glibc-2.39-52/lib64
lrwxrwxrwx 907 root root 3 Jan 1 1970 /nix/store/shybiq9nx8j3sp3ax2gb6c4lni1djabl-glibc-2.39-52/lib64 -> lib
THe change ignores `IsADirectoryError` for this case.
- - - - -
1 changed file:
- diffoscope/comparators/utils/file.py
Changes:
=====================================
diffoscope/comparators/utils/file.py
=====================================
@@ -364,11 +364,15 @@ class File(metaclass=abc.ABCMeta):
# eg. invalid symlink
return None
- h = tlsh.Tlsh()
- with open(self.path, "rb") as f:
- for buf in iter(lambda: f.read(32768), b""):
- h.update(buf)
- h.final()
+ try:
+ h = tlsh.Tlsh()
+ with open(self.path, "rb") as f:
+ for buf in iter(lambda: f.read(32768), b""):
+ h.update(buf)
+ h.final()
+ except IsADirectoryError:
+ # file is a symlink to a directory
+ return None
try:
return h.hexdigest()
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/f545e70a63f3c7d554b96197de40837fa7969f65
--
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/f545e70a63f3c7d554b96197de40837fa7969f65
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/20240824/957d7b58/attachment.htm>
More information about the rb-commits
mailing list