diff --git a/gallery_dl/downloader/http.py b/gallery_dl/downloader/http.py index 8ea6a007..703dcca1 100644 --- a/gallery_dl/downloader/http.py +++ b/gallery_dl/downloader/http.py @@ -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( diff --git a/test/test_downloader.py b/test/test_downloader.py index f6c3dbea..fb442c49 100644 --- a/test/test_downloader.py +++ b/test/test_downloader.py @@ -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()