From 67c650e3a0fd53b176ac086daf9244f6c13713f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Thu, 21 Dec 2017 13:47:46 +0100 Subject: [PATCH] fix: Also skip non-existing files. --- filecheck/filecheck.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/filecheck/filecheck.py b/filecheck/filecheck.py index 33ef626..57c9ce0 100644 --- a/filecheck/filecheck.py +++ b/filecheck/filecheck.py @@ -241,7 +241,7 @@ class File(FileBase): def _compute_random_hashes(self): """Compute a random amount of hashes at random positions in the file to ensure integrity after the copy (mitigate TOCTOU attacks)""" - if self.maintype == 'image' or os.path.isdir(self.src_path): + if not os.path.exists(self.src_path) or os.path.isdir(self.src_path) or self.maintype == 'image': # Images are converted, no need to compute the hashes return self.random_hashes = [] @@ -266,7 +266,7 @@ class File(FileBase): def _validate_random_hashes(self): """Validate hashes computed by _compute_random_hashes""" - if self.maintype == 'image' or os.path.isdir(self.src_path): + if not os.path.exists(self.src_path) or os.path.isdir(self.src_path) or self.maintype == 'image': # Images are converted, we don't have to fear TOCTOU return True for start_pos, hashed_src in self.random_hashes: