[dl:http] fail downloads of empty files (#8661)

This commit is contained in:
Mike Fährmann
2025-12-09 10:07:30 +01:00
parent ae41de3be5
commit efad90696d
2 changed files with 17 additions and 2 deletions

View File

@@ -230,6 +230,10 @@ class HttpDownloader(DownloaderBase):
# check file size
size = text.parse_int(size, None)
if size is not None:
if not size:
self.release_conn(response)
self.log.warning("Empty file")
return False
if self.minsize and size < self.minsize:
self.release_conn(response)
self.log.warning(

View File

@@ -298,6 +298,15 @@ class TestHTTPDownloader(TestDownloaderBase):
self.assertTrue(success)
self.assertEqual(pathfmt.temppath, "")
def test_http_empty(self):
url = f"{self.address}/~NUL"
pathfmt = self._prepare_destination(None, extension=None)
with self.assertLogs(self.downloader.log, "WARNING") as log_info:
success = self.downloader.download(url, pathfmt)
self.assertFalse(success)
self.assertEqual(log_info.output[0],
"WARNING:downloader.http:Empty file")
class TestTextDownloader(TestDownloaderBase):
@@ -400,6 +409,7 @@ SAMPLES = {
("blend", b"BLENDER-v303RENDH"),
("obj" , b"# Blender v3.2.0 OBJ File: 'foo.blend'"),
("clip", b"CSFCHUNK\x00\x00\x00\x00"),
("~NUL", b""),
}
@@ -428,8 +438,9 @@ def generate_tests():
return test
for idx, (ext, content) in enumerate(SAMPLES):
test = generate_test(idx, ext, content)
setattr(TestHTTPDownloader, test.__name__, test)
if ext[0].isalnum():
test = generate_test(idx, ext, content)
setattr(TestHTTPDownloader, test.__name__, test)
generate_tests()