Skip to content

Commit 5aa5036

Browse files
committed
fix(handlers): handle dangling symlinks in MultiFile handlers.
MultiFile handlers would collect files within a directory corresponding to a specific schema without checking if those files are actually present. For example, a directory could contain dangling symlinks with a name corresponding to the glob search. This would lead to FileNotFoundError being thrown by the multi-file handlers.
1 parent 2e6a7ae commit 5aa5036

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

unblob/handlers/archive/sevenzip.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ def calculate_multifile(self, file: Path) -> Optional[MultiFile]:
117117
size = calculate_sevenzip_size(header)
118118
logger.debug("Sevenzip header", header=header, size=size, _verbosity=3)
119119

120-
paths = sorted(file.parent.glob(f"{file.stem}.*"))
120+
paths = sorted(
121+
[p for p in file.parent.glob(f"{file.stem}.*") if p.resolve().exists()]
122+
)
121123

122124
files_size = sum(path.stat().st_size for path in paths)
123125
logger.debug(

unblob/handlers/compression/gzip.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ def is_valid_gzip(self, path: Path) -> bool:
166166
return True
167167

168168
def calculate_multifile(self, file: Path) -> Optional[MultiFile]:
169-
paths = sorted(file.parent.glob(f"{file.stem}.*"))
169+
paths = sorted(
170+
[p for p in file.parent.glob(f"{file.stem}.*") if p.resolve().exists()]
171+
)
170172

171173
# we 'discard' paths that are not the first in the ordered list,
172174
# otherwise we will end up with colliding reports, one for every

0 commit comments

Comments
 (0)