Skip to content

Commit be993c9

Browse files
committed
fix(multi-gzip) is_valid_gzip dies on empty file
Reported by @AndrewFasano: extracting the file http://ixp.mikrotik.co.id/download/archive/6.18/all_packages-mipsbe-6.18.zip results in 2024-02-25 03:31.49 [warning ] Unhandled Exception during multi file calculation handler=multi-gzip path=all_packages-mipsbe-6.18.zip_extract/system-6.18-mipsbe.npk_extract/4096-5779456.squashfs_v4_le_extract/home/web/webfig/index.html.gz.nocache pid=2582003 severity=<Severity.ERROR: 'ERROR'> Traceback (most recent call last): File "/unblob/unblob/processing.py", line 377, in _calculate_multifile return dir_handler.calculate_multifile(path) File "/unblob/unblob/handlers/compression/gzip.py", line 179, in calculate_multifile if self.is_valid_gzip(file): File "/unblob/unblob/handlers/compression/gzip.py", line 159, in is_valid_gzip with File.from_path(path) as f: File "/unblob/unblob/file_utils.py", line 58, in from_path m = cls(base_file.fileno(), 0, access=access) ValueError: cannot mmap an empty file
1 parent 4058608 commit be993c9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from pathlib import Path
2+
3+
from unblob.handlers.compression.gzip import MultiVolumeGzipHandler
4+
5+
6+
def test_multivolume_is_valid_gzip_empty_file(tmp_path: Path):
7+
empty = tmp_path / "empty"
8+
empty.touch()
9+
assert not MultiVolumeGzipHandler().is_valid_gzip(empty)

unblob/handlers/compression/gzip.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,12 @@ class MultiVolumeGzipHandler(DirectoryHandler):
156156
PATTERN = Glob("*.gz.*")
157157

158158
def is_valid_gzip(self, path: Path) -> bool:
159-
with File.from_path(path) as f:
159+
try:
160+
file = File.from_path(path)
161+
except ValueError:
162+
return False
163+
164+
with file as f:
160165
try:
161166
fp = SingleMemberGzipReader(f)
162167
if not fp.read_header():

0 commit comments

Comments
 (0)