Skip to content
Snippets Groups Projects
Forked from Reproducible Builds / diffoscope
Source project has a limited visibility.
  • Sergei Trofimovich's avatar
    f545e70a
    file: don't crash when hashing directory symlinks · f545e70a
    Sergei Trofimovich authored
    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.
    f545e70a
    History
    file: don't crash when hashing directory symlinks
    Sergei Trofimovich authored
    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.